473,651 Members | 3,024 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

typedef /struct and the scope problems

lets say I have a header file :

struct AAAA
{
blabla.....
};
typedef struct AAAA A;
typedef struct BBB
{
blabla...
.....
} B;
I try to compile it and get an error message that "AAA" has already
been declared in the current scope ! ( And I checked everywhere it is
not ! )
What's funny is , that when I remove the second typedef it compiles
well.
Any ideas why such a weird behavior ?
Thanks ?

Mar 3 '06 #1
23 5801
On 2006-03-03, my**********@gm ail.com <my**********@g mail.com> wrote:
lets say I have a header file :

struct AAAA
{
blabla.....
};
typedef struct AAAA A;
typedef struct BBB
{
blabla...
.....
} B;
I try to compile it and get an error message that "AAA" has already
been declared in the current scope ! ( And I checked everywhere it is
not ! )
What's funny is , that when I remove the second typedef it compiles
well.
Any ideas why such a weird behavior ?
Thanks ?


No idea. What compiler are you using, it may be broken
Mar 3 '06 #2
"my**********@g mail.com" <my**********@g mail.com> writes:
lets say I have a header file :

struct AAAA
{
blabla.....
};
typedef struct AAAA A;
typedef struct BBB
{
blabla...
.....
} B;
I try to compile it and get an error message that "AAA" has already
been declared in the current scope ! ( And I checked everywhere it is
not ! )
What's funny is , that when I remove the second typedef it compiles
well.
Any ideas why such a weird behavior ?


That's odd, I get a parse error on "blabla.... .".

If I fix the syntax errors, it compiles without error. Obviously the
error is in code you haven't bothered to show us (probably on line
42).

If you post a complete compilable source file that exhibits the
problem, we can probably help. If not, we're not mindreaders.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Mar 3 '06 #3
Intel's one.

Mar 3 '06 #4
struct float
{
int e;
int m;
};

typedef struct float A;

typedef struct BBB
{
A floatA;
} B;

Mar 3 '06 #5
"my**********@g mail.com" <my**********@g mail.com> writes:
Intel's one.


Intel's one what?

Please read <http://cfaj.freeshell. org/google/> (that URL has been
posted here hundreds of times).

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Mar 3 '06 #6
"my**********@g mail.com" <my**********@g mail.com> writes:
struct float
{
int e;
int m;
};

typedef struct float A;

typedef struct BBB
{
A floatA;
} B;


Without context (see <http://cfaj.freeshell. org/google/>), it's
difficult to know what you're asking about this code.

But the fact that "float" is a reserved word is going to cause some
problems. You didn't mention any syntax errors in your original post.
Is this *really* the exact code that you compiled? If not, please
post the exact code (copy-and-paste it, *don't* re-type it) and
provide enough context so we can figure out why you're showing it to
us.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Mar 3 '06 #7
ok _float instead of float :) , names aside ....
struct _float
{
int e;
int m;
};

typedef struct _float A;

typedef struct BBB
{
A floatA;
} B;


removing
typedef struct _float A;

and using :
struct _float floatA
will compile .... still why this typedef line creates problems.

Mar 4 '06 #8
my**********@gm ail.com wrote:
ok _float instead of float :) , names aside ....
struct _float
{
int e;
int m;
};

typedef struct _float A;

typedef struct BBB
{
A floatA;
} B;


removing
typedef struct _float A;

and using :
struct _float floatA
will compile .... still why this typedef line creates problems.


There is no problem. It compiles fine here.
If you want further help, I suggest you post the /actual/
code. Then you post the actual command line used to compile it,
and the output/errors that produces.
Mar 4 '06 #9
"my**********@g mail.com" wrote:

ok _float instead of float :) , names aside ....
struct _float
{
int e;
int m;
};

typedef struct _float A;

typedef struct BBB
{
A floatA;
} B;


removing
typedef struct _float A;

and using :
struct _float floatA
will compile .... still why this typedef line creates problems.


Don't alter material you quote. Do preserve attribution lines for
any quoted material. Do snip anything not germane to your reply.

_float is an identifier reserved for the implementation. You
should not use it. In general, do not use any identifiers that
begin with a '_' (although that is slight overkill).

--
"If you want to post a followup via groups.google.c om, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell. org/google/>
Also see <http://www.safalra.com/special/googlegroupsrep ly/>

Mar 4 '06 #10

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

Similar topics

7
2140
by: Tony Johansson | last post by:
Hello Experts! I have the following Array template class see below. I execute these three statements statement 1: Array<int> x(5); statement 2: cin >>x; statement 3: Array<int>::element_type y = x; but I can't understand the last one which is Array<int>::element_type y = x; We have a typedef T element_type; in the template Array class see below
21
3851
by: Roshan Naik | last post by:
typedef int foo ( foo ); // foo is a pointer-to-function type that takes another foo as argument and returns an int I need to achieve the above effect somehow. This is not accepted by any compiler I have tried, even though I cant spot anything in the standard that restricts it. Is there a way to achieve this typedefintion using metaprogramming ? I noticed that boost::variant does some metaprogramming tricks to allow
8
2372
by: J Krugman | last post by:
My compiler complains if I do something like this typedef struct { node *next; } node; but it's OK with typedef struct superfluous_identifier { superfluous_identifier *next;
2
3051
by: Immo Birnbaum | last post by:
Hi, I'm trying to solve a programming lab assignment for my college C programming course, but as they taught us two semesters of Java before teaching us any C, I'm having problems with all the aspects of pointers. I'd appreciate if anybody could help me with the following problem: I tried to learn how to use malloc, free, and the * and & operators. I started with a few simple lines of code like:
16
3824
by: burn | last post by:
Hello, i am writing a program under linux in c and compile my code with make and gcc. Now i have 4 files: init.c/h and packets.c/h. Each header-file contains some: init.h: struct xyz {
7
2454
by: Dennis Myrén | last post by:
Hi. Is there any way to define an alias for a type like you could in C++: typedef int NUMBER; I tried using #define but that did not work. Thank you. -- Regards,
8
2352
by: Ronny Mandal | last post by:
Consider these two: Typedef struct { int foo, bar } FooBar; struct FooBar { int foo, bar }; What woul be the only difference here; just that I can create new instances by 'Foobar fb, *pfb', and the second demands that I prefix with struct? struct FooBar fb, *pfb?
15
2559
by: Ian Bush | last post by:
Hi All, I'm a bit confused by the following which is causing one of our user's codes fail in compilation: typedef struct SctpDest_S; 1) Is this standard ? 2) If so ( or even if not so ! ) what is it supposed to do ?
17
3301
by: Steve Carter | last post by:
Can someone please explain why the following is not possible? typedef foobar { int x; foobar *next; /* why can't we do this? */ }; Thanks
0
8361
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
8278
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8701
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8466
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8584
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
7299
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
5615
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
1912
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1588
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.