the static identifier in the global scope

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • parag_paul@hotmail.com

    the static identifier in the global scope

    hi All
    for the following

    #include <stdio.h>
    typedef struct{
    int a ;
    int b[100];
    char* j;
    } AST;

    static AST a;


    Now is there any need for the static identifier?
    -Parag
  • Ian Collins

    #2
    Re: the static identifier in the global scope

    parag_paul@hotm ail.com wrote:
    hi All
    for the following
    >
    #include <stdio.h>
    typedef struct{
    int a ;
    int b[100];
    char* j;
    } AST;
    >
    static AST a;
    >
    >
    Now is there any need for the static identifier?
    Where do you want a to be visible? Any decent C book will explain this.

    --
    Ian Collins.

    Comment

    • Richard Heathfield

      #3
      Re: the static identifier in the global scope

      parag_paul@hotm ail.com said:
      hi All
      for the following
      >
      #include <stdio.h>
      typedef struct{
      int a ;
      int b[100];
      char* j;
      } AST;
      >
      static AST a;
      >
      >
      Now is there any need for the static identifier?
      No. There isn't even any need for the object or the type, because they are
      not used by the (non-existent) program.

      Code does not exist in a vacuum. Whether you use static qualification
      depends on what you're trying to achieve, and we're not mind readers.

      --
      Richard Heathfield <http://www.cpax.org.uk >
      Email: -http://www. +rjh@
      Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
      "Usenet is a strange place" - dmr 29 July 1999

      Comment

      • Jack Klein

        #4
        Re: the static identifier in the global scope

        On Fri, 11 Apr 2008 01:46:45 -0700 (PDT), "parag_paul@hot mail.com"
        <parag_paul@hot mail.comwrote in comp.lang.c:
        hi All
        for the following
        >
        #include <stdio.h>
        typedef struct{
        int a ;
        int b[100];
        char* j;
        } AST;
        >
        static AST a;
        First, C does not have anything called a "global scope". The snipped
        you have shown, if it were compiled, has the definition of an unnamed
        structure type, the definition of an alias for that type, and the
        definition of an object of this structure type with internal linkage,
        all at "file scope", which is the largest scope that C has.

        Secondly, even if there is no other definition of that structure type
        in other translation units, there still could be another identifier
        named "a" with external linkage in other translation units, which
        could cause a problem if the static keyword is removed from the object
        definition, giving this identifier "a" external linkage.

        --
        Jack Klein
        Home: http://JK-Technology.Com
        FAQs for
        comp.lang.c http://c-faq.com/
        comp.lang.c++ http://www.parashift.com/c++-faq-lite/
        alt.comp.lang.l earn.c-c++

        Comment

        Working...