Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ Moderated > Re: same name f...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 3 of 4 Topic 9513 of 9831
Post > Topic >>

Re: same name for types and variables

by Marco Manfredini <ok_nospam_ok@[EMAIL PROTECTED] > Apr 18, 2008 at 05:15 PM

Oncaphillis wrote:

[does not work:]
> typedef int bar;
> 
> struct foo {
>    bar bar;
> };
> 1. Is this behavior part of the standard or a defect

I think this is standard behavior. There is a rule for class-scope
declarations in 3.3.6 which basically says, that a declaration is only
valid, if it yields the same declaration after seeing all of the class.
This prohibits redefining a symbol after using it.

> 
> 2. Is there a more elegant (may be even ****table) way
>     to compile these C-headers without having to change
>     them.

Not really. It might be a bit more elegant not to duplicate everything
in the headers, but just to wrap all occurrences of a typename in a
macro:
#ifdef __cplusplus__
#define TYPESYM(X) X##_t 
#else 
#define TYPESYM(X) 
#endif

typedef int TYPESYM(bar);
struct TYPESYM(foo) {
TYPESYM(bar) bar; 
};



-- 
      [ See http://www.gotw.ca/resources/clcm.htm
for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
 




 4 Posts in Topic:
same name for types and variables
Oncaphillis <oncaphill  2008-04-17 11:39:21 
Re: same name for types and variables
red floyd <no.spam@[EM  2008-04-18 06:13:15 
Re: same name for types and variables
Marco Manfredini <ok_n  2008-04-18 17:15:07 
Re: same name for types and variables
Oncaphillis <oncaphill  2008-04-18 17:20:00 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Jul 26 2:48:59 CDT 2008.