473,387 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Scope Rules

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
3 4110
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

33
by: Arthur | last post by:
>>>a= >>> for p in a: print p 1 2 3 >>> p 3 My naive expectation was that p would be 'not defined' from outside
0
by: Andrew Collier | last post by:
Hello, I was writing a program which used some nested functions, and came across a behaviour which I was unable to explain. I can summarise it with the example below: #!/usr/bin/env python
4
by: J.J.García | last post by:
Hi, I have defined an static operator in a class, and when I try to use it inside of the class, my compiler --Visual C++ 7.1-- complains saying that there not exist an operator that suits the...
3
by: n2xssvv g02gfr12930 | last post by:
Although I rarely if ever have a problem with scope, I was wondering whether anybody knows of good reference, (book, web page, etc), that covers scope rules. Hopefully this will be helpful to...
1
by: Tim Haughton | last post by:
Firstly, if there's a better newsgroup to ask this on, feel free to redirect me. I have these requirements of WDS for a project: 1) I need to be able to add a new location to the user scope...
1
by: Cousson, Benoit | last post by:
Hi, I'd like to be able to use a nested class (C1) from another sibling nested class (C3). This looks very similar to the nested scopes of functions except that it does not work. class...
0
by: Maric Michaud | last post by:
Le Tuesday 12 August 2008 11:29:18 Cousson, Benoit, vous avez écrit : This is a language limitation. This is because nested scope is implemented for python function only since 2.3 allow late...
0
by: Cousson, Benoit | last post by:
This is a language limitation. That was my understanding as well, but I think it is a pity to have that limitation. Don't you think that the same improvement that was done for method nested scope...
1
by: Giacomo Catenazzi | last post by:
Hello, To learn the details of C, I've build the following example, could you check if it is correct and if it miss some important cases? Are there some useful (real cases) examples of: -...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.