Accessing vars in global and module scope in ANSI C 
Author Message
 Accessing vars in global and module scope in ANSI C

Newsgroups: comp.lang.c
Path: seunet!sunic!!!!

Lines: 41

pointer pointing to the |: global variables (static or external linkage). But,
if you do have |: the sources available, why not change the names of those
local |: variables instead? Having identical names for local variables |: _and_
wanting to access global variables with the same name is |: quite unreadable I
might say ...

|This is purely an academic example of scoping rules in ANSI C. It is not |ment
as a suggestion as to an implementation methodology people should |use for
their variable naming conventions.

Ok, academic examples and questions are easy ;-) Have a look at the Standard: Scope of identifiers

`If an outer declaration of a lexically identical identifier exists  in the
same name space, it is hidden until the current scope terminates, after which
it again becomes visible.'

This is just a formal way of saying that:

        int x;

        int foo() {

        int x;

        /* the global variable `x' cannot be accessed
         * within this function directly


I guess this about says it all ...

kind regards,

|Fidonet:  Jos Horsmeier 2:201/200

| Standard disclaimer: The views of this user are strictly his own.

Thu, 09 Oct 1997 03:00:00 GMT  
 [ 1 post ] 

 Relevant Pages 

1. Accessing vars in global and module scope in ANSI C

2. global vars vs: local vars

3. ANSI C and global variable scope

4. how to access local and global vars in a function

5. Accessing vars in global

6. Module scope variables visible in other Modules?

7. global/static vars inside loops

8. const global vars

9. Global vars versus pointers

10. global vs local vars

11. global/static vars inside loops

12. static global vars and functions


Powered by phpBB® Forum Software