|
|
|
|
||||||
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
parag_paul@hotmail.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. |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
parag_paul@hotmail.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 |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
On Fri, 11 Apr 2008 01:46:45 -0700 (PDT), "parag_paul@hotmail.com"
<parag_paul@hotmail.com> wrote 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.learn.c-c++ http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html |
|
![]() |
| Outils de la discussion | |
|
|