Scope and Lifetime

Questions

  • 1

    register keyword

    bambhole
    Reply

    why global variable can’t be declared with register keyword??

  • 0

    keyword

    bambhole
    Reply

    why global variable can’t be declared with register keyword?

  • 1

    Which error exactly?

    vrundapro
    Reply

    At 51.07 Its which error? Compiler error or linking error?You have mentioned both.confused!

    • vrundapro

      Sorry got it. Linking error

  • 3

    At 1.22.42 you have written 10 10 as output for static but i think its 5 10 as g() is surrounded by f()

    sanjaytwo
    Reply

    Is there any mistake??

    • kabbupro19

      ya i have same doubt .can we write like this?

      f()

      {

      int x=5;

      {

      print x;

      }

      }

       

    • getgatebook

      @sanjaytwo
      g(){} is not enclosed by f() {} in the program. function call g() is enclosed instead.

    • getgatebook

      @kabbupro19

      Can you elaborate your question ?
      Please go through the reply given to @sanjaytwo in this same thread

       

  • 1

    sir what does linking time means ?what u mean by linking?52;20

    adharpro
    Reply

    i cannot get what is linking

    • souradeeppro19

      Linking here, means that when a program is distributed in several files, during compilation , the compiler will link all the parts of the program for its execution.
      So, when it sees that ‘static int x’ is declared as extern, it can’t find ‘x’ in other files as ‘static int x’ gets hidden.

  • 1

    sir what does linking time means ?what u mean by linking?52;20

    adharpro
    Reply

    i cannot get what is linking?u said first compilation then linking then execution?what is linking

    • getgatebook

      Linking is the final stage of compilation. It takes one or more object files or libraries as input and combines them to produce a single (usually executable) file. In doing so, it resolves references to external symbols, assigns final addresses to procedures/functions and variables, and revises code and data to reflect new addresses (a process called relocation).

  • 3

    Global Register variable

    nidhipro19
    Reply

    According to the content provided through the link, “The register name must be a valid register name for the target platform”. So how can we fetch register name to declare global variable as register??

    • getgatebook

      There will be manual for every target machine. we need to find the register names from that.

    • nidhipro19

      Means, if I want to declare variable as register then to find out valid register name, it will be provided in kind of user manuals??

    • getgatebook

      Yes