|
|
|
|
||||||
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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)? |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
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. |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
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'. |
|
![]() |
| Outils de la discussion | |
|
|