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 > 'static' to make object accessible by file
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
'static' to make object accessible by file

Réponse
 
LinkBack Outils de la discussion
Vieux 12/04/2008, 04h45   #1
Lax
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 'static' to make object accessible by file


Say we have a static external object (object defined outside of any
block with static qualifier) in a file.
We are telling the compiler that we intend that object to be accessed
by functions in the current file that are below the definition.

Now what if one of these functions passes a pointer value to this
object to a function in another file, and that function uses the
pointer to access this static object? Is this 'normal' or dependent on
the specific environment?

This works on my system but I am not sure if this is a normal thing I
should be doing or it's just because my environment/compiler isn't
picking up on the bad move. If it's okay, is it bad style?

So, does the C standard say that such a move is allowed (either
directly or indirectly by not saying that it is disallowed)?

  Réponse avec citation
Vieux 12/04/2008, 04h50   #2
Ian Collins
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: 'static' to make object accessible by file

Lax wrote:
> Say we have a static external object (object defined outside of any
> block with static qualifier) in a file.
> We are telling the compiler that we intend that object to be accessed
> by functions in the current file that are below the definition.
>
> Now what if one of these functions passes a pointer value to this
> object to a function in another file, and that function uses the
> pointer to access this static object? Is this 'normal' or dependent on
> the specific environment?


Normal. A static object does not have global linkage, but it still has
to exist somewhere.

--
Ian Collins.
  Réponse avec citation
Vieux 12/04/2008, 05h08   #3
Walter Roberson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: 'static' to make object accessible by file

In article <78b1bedd-a17a-4c65-9a28-cbab26648da7@e39g2000hsf.googlegroups.com>,
Lax <Lax.Clarke@gmail.com> wrote:

>Say we have a static external object (object defined outside of any
>block with static qualifier) in a file.
>We are telling the compiler that we intend that object to be accessed
>by functions in the current file that are below the definition.


>Now what if one of these functions passes a pointer value to this
>object to a function in another file, and that function uses the
>pointer to access this static object? Is this 'normal' or dependent on
>the specific environment?


That is normal and allowed. There are lurking dangers, such as if
the static data is declared const but the routines do not consistantly
use the const qualifier and ending up modifying the data.
--
'Roberson' is my family name; my given name is 'Walter'.
  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 19h20.


É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,07768 seconds with 11 queries