PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.c > the static identifier in the global scope
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
the static identifier in the global scope

Réponse
 
LinkBack Outils de la discussion
Vieux 11/04/2008, 09h46   #1
parag_paul@hotmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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
  Réponse avec citation
Vieux 11/04/2008, 09h57   #2
Ian Collins
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: the static identifier in the global scope

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.
  Réponse avec citation
Vieux 11/04/2008, 10h03   #3
Richard Heathfield
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: the static identifier in the global scope

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
  Réponse avec citation
Vieux 12/04/2008, 04h59   #4
Jack Klein
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: the static identifier in the global scope

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
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 19h09.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,10962 seconds with 12 queries