static

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • vim

    #1

    static

    hello guys



    plz tel me the differances between global static and local static.
    If possible with examples

  • Eric Sosman

    #2
    Re: static

    vim wrote:
    hello guys
    >
    >
    >
    plz tel me the differances between global static and local static.
    If possible with examples
    Please explain what you mean by "global static" and "local
    static," because the Standard that defines the C language does
    not use either phrase.

    --
    Eric Sosman
    esosman@acm-dot-org.invalid

    Comment

    • vim

      #3
      Re: static

      On Mar 22, 8:34 pm, Eric Sosman <esos...@acm-dot-org.invalidwrot e:
      vim wrote:
      hello guys
      >
      plz tel me the differances between global static and local static.
      If possible with examples
      >
      Please explain what you mean by "global static" and "local
      static," because the Standard that defines the C language does
      not use either phrase.
      >
      --
      Eric Sosman
      esos...@acm-dot-org.invalid





      Global static variable is a variable declared(with "static" keyword)
      outside function.Local is declared inside any function with "static"
      keyword.

      Comment

      • osmium

        #4
        Re: static

        "Eric Sosman" writes:
        vim wrote:
        >hello guys
        >>
        >>
        >>
        >plz tel me the differances between global static and local static.
        >If possible with examples
        >
        Please explain what you mean by "global static" and "local
        static," because the Standard that defines the C language does
        not use either phrase.
        I normally leave such question to the language mavens.

        A variable declared as static within a function preserves information
        between successive calls to that function. For example, a random number
        generator(1) can preserve the seed to be used to generate the next number.

        A variable or function declared as static external to any function "hides"
        the item from code in other source files(2), thus preventing inadvertent -
        or perhaps malicious, usage. By default functions are "known" everywhere
        and variables *can* be known by use of an extern qualifier(3) by the
        *receiver*, not the giver.

        Function declarations *can* be made within a function, but it is a rarely
        used style. My guess is that the addition of static would have no effect.
        ............... ..
        (1) Yes I know the generator does not generate random numbers. Get a life
        fer crissakes!!
        (2) Yes I know the dammed thing is called a translation unit!
        (3) The proper name may not actually be "qualifier" . Despite that, a
        person speaking ordinary English would understand.


        Comment

        • Eric Sosman

          #5
          Re: static

          vim wrote:
          On Mar 22, 8:34 pm, Eric Sosman <esos...@acm-dot-org.invalidwrot e:
          >vim wrote:
          >>hello guys
          >>plz tel me the differances between global static and local static.
          >>If possible with examples
          > Please explain what you mean by "global static" and "local
          >static," because the Standard that defines the C language does
          >not use either phrase.
          >>
          >--
          >Eric Sosman
          >esos...@acm-dot-org.invalid
          >
          >
          >
          >
          >
          >
          Global static variable is a variable declared(with "static" keyword)
          outside function.Local is declared inside any function with "static"
          keyword.
          >

          Comment

          • Eric Sosman

            #6
            Re: static

            vim wrote:
            On Mar 22, 8:34 pm, Eric Sosman <esos...@acm-dot-org.invalidwrot e:
            >vim wrote:
            >>hello guys
            >>plz tel me the differances between global static and local static.
            >>If possible with examples
            > Please explain what you mean by "global static" and "local
            >static," because the Standard that defines the C language does
            >not use either phrase.
            >
            Global static variable is a variable declared(with "static" keyword)
            outside function.Local is declared inside any function with "static"
            keyword.
            Both variables have the same storage duration, but they
            differ in scope and in linkage. The scope of the file-scope
            variable ("global static") extends from its declaration to
            the end of the translation unit, while that of the block-scope
            variable ("local static") extends from its declaration to the
            end of the block containing it (both scopes can be "interrupte d"
            by inner declarations). The file-scope variable has internal
            linkage, while the block-scope variable has no linkage.

            --
            Eric Sosman
            esosman@acm-dot-org.invalid

            Comment

            • Ben Pfaff

              #7
              Re: static

              "osmium" <r124c4u102@com cast.netwrites:
              Function declarations *can* be made within a function, but it is a rarely
              used style. My guess is that the addition of static would have no effect.
              It would be a constraint violation. See C99 6.7.1:

              The declaration of an identifier for a function that has
              block scope shall have no explicit storage-class specifier
              other than extern.
              --
              "I've been on the wagon now for more than a decade. Not a single goto
              in all that time. I just don't need them any more. I don't even use
              break or continue now, except on social occasions of course. And I
              don't get carried away." --Richard Heathfield

              Comment

              Working...