473,406 Members | 2,371 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,406 software developers and data experts.

name space and typedef


typedef int myint;

struct s
{
myint myint; /* 1 */
} s;

int main()
{
myint myint; /* 2 */
s.myint = 5; /* 1 */
myint = 1; /* 2 */
return myint; /*kill warning*/
}

What is interesting to me is case 2. "Typedef myint" and "object myint"
identifiers belong to the same name space, so I think there should
be a conflict (there's no conflict in case 1 - members have a name
space of their own). However, two compilers accepted the above code.

--
Stan Tobias
mailx `echo si***@FamOuS.BedBuG.pAlS.INVALID | sed s/[[:upper:]]//g`
Nov 14 '05 #1
1 1406
In article <37*************@individual.net>
S.Tobias <si***@FamOuS.BedBuG.pAlS.INVALID> wrote:
typedef int myint;

struct s
{
myint myint; /* 1 */
} s;

int main()
{
myint myint; /* 2 */
s.myint = 5; /* 1 */
myint = 1; /* 2 */
return myint; /*kill warning*/
}

What is interesting to me is case 2. "Typedef myint" and "object myint"
identifiers belong to the same name space, so I think there should
be a conflict (there's no conflict in case 1 - members have a name
space of their own). However, two compilers accepted the above code.


They are indeed in the same name-space; but the declaration of the
block-scope variable in "2" is in an inner scope, which hides the
outer-scope name. This is therefore no different than:

int i;
int f(void) {
int i;
...
}

or, perhaps even closer but C99-specific:

int i;
int f(void) {
i = 3; /* sets the file-scope i */
int i = 2; /* creates a new i */
i = 1; /* sets the block-scope i */
...
}

(Actually *implementing* "myint myint;" in C compilers tends to be
pretty tricky, while implementing the scoped "i"s tends to be easy,
but this is an artifact of typical C implementations.)
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.
Nov 14 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: ja | last post by:
Hello, I have a table that has a name field with the following data john doe john doe smith john d smith I need to separate the first, middle and last names into separate fields. ex....
3
by: Eric Lilja | last post by:
Hello, got an odd question. I need a good typedef name for the type: std::vector<std::vector<std::pair<std::string, std::string> > > Even with using-statements to get rid of std:: it's simply too...
37
by: hasadh | last post by:
Hello, probably this may be a simple qn to u all but I need an answer plz. In my software i used macros like OK,TRUE,FALSE,FAILURE . A friend who included this code as a library into his module...
5
by: Janice | last post by:
Always get segmentation fault for the following code. If the data is primitive type instead, it will be fine. What is the problem? Thanx main(){ typedef int pid_t; pid_t pid=12; pid_t* ary;...
11
by: Mateusz Loskot | last post by:
Hi, I have a simple question about naming convention, recommeded names or so in following case. I have a class which is implemented with one of STL container (aggregated) and my aim is to...
1
by: syntheticpp | last post by:
Here a compiler bug of msvc 8 (14.00.50727.42): fatal error C1060: compiler is out of heap space Without the virtual inheritance it compiles fine. GCC has no problems. Code (tested with...
17
by: Jellicle | last post by:
There are some sturct arrays (or struct vectors), such as: struct S1_t { double keyField ; ..// other fields } S1_t s1;
20
by: ramasubramanian.rahul | last post by:
hi folks i have a peculiar problem. i have to allocate more than size_t consequtive bytes on a system . after i do a malloc .. i am unable to do a realloc because it takes size_t as a new size...
185
by: jacob navia | last post by:
Hi We are rewriting the libc for the 64 bit version of lcc-win and we have added a new field in the FILE structure: char *FileName; fopen() will save the file name and an accessor function will...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.