473,796 Members | 2,601 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4142
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[]="ABCDEFGHIJKLM NOPQRSTUVWXYZab cdefghijklmnopq rstuvwxyz.\
\n",*q="kl BIcNBFr.NKEzjwC IxNJC";int i=sizeof p/2;char *strchr();int putchar(\
);while(*q){i+= strchr(p,*q++)-p;if(i>=(int)si zeof 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
3558
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
1175
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
1906
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 statement. I have something like this: namespace rend {
3
2138
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 others. JB
1
2356
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 rules for WDS so that it indexes an application specific folder. This folder, at the moment, contains only text files. 2) This folder *should not* be included in any of Vista's searches from the
1
987
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 A(object): pass class B(object): class C1(object):
0
200
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 binding of free variables. the scope in class statment is not a closure, so there is only two possible scope in it : local and global. When "class C2(C1):" statment is interpreted, it is in the scope of class B for which a name C1 exists, but it...
0
154
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 could be done as well for nested class? I can easily fix my current issue by doing the binding after the class declaration. My concern is more about the lack of symmetry of that approach; meaning that if both classes are in the global scope, one...
1
3761
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: - "function prototype scope" for structures and unions? - "extern" for internal linkage ?
0
9685
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10459
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10018
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9055
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5446
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5578
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4120
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3735
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2928
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.