By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,591 Members | 629 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,591 IT Pros & Developers. It's quick & easy.

Scope Rules

P: n/a
are the following rules correct in C89/C90?

----

SCOPE RULES
1) the scope of an identifier declared inside a block is the block in
which it is declared;
2) when you have nested blocks (extern block and internal block), an
identifier declared in the external block is known also in the internal
block, while an identifier declared in the internal block is not known
in the external block; (*)
3) when you have parallel blocks (first block and second block), an
identifier declared in the first block is not known in the second block.

(*)
- for variable names, an identifier declared in the external block is
known also in the internal block only if it is not re-declared in the
internal block
- for function names, an identifier declared in the external block
cannot be re-declared in the internal block

----

these rules are not written in any book; i wrote them myself. i'd only
want to know if they are correct.

thanks.
Apr 16 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
fctk <-> writes:
are the following rules correct in C89/C90?
They are approximately correct for declarations of objects that
occur within a block. They don't correctly cover scopes of other
entities (such as macro names, macro parameters, argument names
in function prototypes, structure, union, or enumeration members,
or label names), nor do they cover declarations outside blocks,
nor do they precisely define where a scope begins.
SCOPE RULES
1) the scope of an identifier declared inside a block is the block in
which it is declared;
2) when you have nested blocks (extern block and internal block), an
identifier declared in the external block is known also in the internal
block, while an identifier declared in the internal block is not known
in the external block; (*)
The terms "internal" and "external" are already used for linkage,
so it's better to use the words "inner" and "outer" here, as the
Standard does.
3) when you have parallel blocks (first block and second block), an
identifier declared in the first block is not known in the second block.
If the objects have external linkage and the same name then they
are the same object.
(*)
- for variable names, an identifier declared in the external block is
known also in the internal block only if it is not re-declared in the
internal block
- for function names, an identifier declared in the external block
cannot be re-declared in the internal block


--
int main(void){char p[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv wxyz.\
\n",*q="kl BIcNBFr.NKEzjwCIxNJC";int i=sizeof p/2;char *strchr();int putchar(\
);while(*q){i+=strchr(p,*q++)-p;if(i>=(int)sizeof p)i-=sizeof p-1;putchar(p[i]\
);}return 0;}
Apr 16 '06 #2

P: n/a
fctk wrote:
are the following rules correct in C89/C90?

----

SCOPE RULES
1) the scope of an identifier declared inside a block is
....the point of its declaration to the end of...
the block in which it is declared;

[...]
August

--
I am the "ILOVEGNU" signature virus. Just copy me to your signature.
This email was infected under the terms of the GNU General Public License.
Apr 16 '06 #3

P: n/a
fctk ha scritto:
are the following rules correct in C89/C90?

SCOPE RULES

[...]


ok, i found this:
http://rm-f.net/~orange/devel/specif...t.html#3.1.2.1
Apr 18 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.