Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Conflicting class keyword

Reply
Thread Tools

Conflicting class keyword

 
 
kiran kumr
Guest
Posts: n/a
 
      01-10-2007
Hi,

we have the following scenario:

1. A header file that is used in multiple modules a c application and a C++
application.
2. This file has a variable named class[SIZE].
3. How do I declare class now without conflicting with the other variable
class in the common header file.

I cannot rename the variable class and getway without including the header
file.

-Regards,


 
Reply With Quote
 
 
 
 
Jacek Dziedzic
Guest
Posts: n/a
 
      01-11-2007
kiran kumr wrote:
> Hi,
>
> we have the following scenario:
>
> 1. A header file that is used in multiple modules a c application and a C++
> application.
> 2. This file has a variable named class[SIZE].
> 3. How do I declare class now without conflicting with the other variable
> class in the common header file.
>
> I cannot rename the variable class and getway without including the header
> file.


Perhaps

#undef class
#define class old_class
#include "old_header.h"
#undef class

Does that count as renaming the variable?

I think this should work, although AFAIK it is illegal to re#define
C++ keywords.

HTH,
- J.
 
Reply With Quote
 
 
 
 
Jim Langston
Guest
Posts: n/a
 
      01-11-2007
"kiran kumr" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi,
>
> we have the following scenario:
>
> 1. A header file that is used in multiple modules a c application and a
> C++
> application.
> 2. This file has a variable named class[SIZE].
> 3. How do I declare class now without conflicting with the other variable
> class in the common header file.
>
> I cannot rename the variable class and getway without including the
> header
> file.
>
> -Regards,


If each compiliation unit is to have it's own copy of the variable then make
it static.
static whatever class[SIZE];

If each compiliation unit is to share the one instance of the variable, then
declare it external:
extern whatever class[SIZE];

and in one, and only one, compilation unit (one of the .cpp files) declare
it as a normal global variable:
whatever class[SIZE];



 
Reply With Quote
 
Colander
Guest
Posts: n/a
 
      01-11-2007
Jim Langston wrote:

> "kiran kumr" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Hi,
> >
> > we have the following scenario:
> >
> > 1. A header file that is used in multiple modules a c application and a
> > C++
> > application.
> > 2. This file has a variable named class[SIZE].
> > 3. How do I declare class now without conflicting with the other variable
> > class in the common header file.
> >
> > I cannot rename the variable class and getway without including the
> > header
> > file.
> >
> > -Regards,

>
> If each compiliation unit is to have it's own copy of the variable then make
> it static.
> static whatever class[SIZE];
>
> If each compiliation unit is to share the one instance of the variable, then
> declare it external:
> extern whatever class[SIZE];
>
> and in one, and only one, compilation unit (one of the .cpp files) declare
> it as a normal global variable:
> whatever class[SIZE];


I think you overlooked that in C++ class is an keyword, in C it isn't.

so Legal c code:
int class = 42;
And illegal C++ code:
int class = 42;

Yes there are things that C can do that C++ can't...

 
Reply With Quote
 
BobR
Guest
Posts: n/a
 
      01-11-2007

Colander wrote in message ...
>Jim Langston wrote:
>> If each compiliation unit is to have it's own copy of the variable then

make
>> it static.
>> static whatever class[SIZE];
>> If each compiliation unit is to share the one instance of the variable,

then
>> declare it external:
>> extern whatever class[SIZE];
>> and in one, and only one, compilation unit (one of the .cpp files) declare
>> it as a normal global variable:
>> whatever class[SIZE];

>
>I think you overlooked that in C++ class is an keyword, in C it isn't.
>
>so Legal c code:
>int class = 42;
>And illegal C++ code:
>int class = 42;
>
>Yes there are things that C can do that C++ can't...


So, in C, this is legal?

int struct = 42;

--
Bob R
POVrookie


 
Reply With Quote
 
Jim Langston
Guest
Posts: n/a
 
      01-12-2007

"BobR" <(E-Mail Removed)> wrote in message
news:0Lzph.691980$(E-Mail Removed)...
>
> Colander wrote in message ...
>>Jim Langston wrote:
>>> If each compiliation unit is to have it's own copy of the variable then

> make
>>> it static.
>>> static whatever class[SIZE];
>>> If each compiliation unit is to share the one instance of the variable,

> then
>>> declare it external:
>>> extern whatever class[SIZE];
>>> and in one, and only one, compilation unit (one of the .cpp files)
>>> declare
>>> it as a normal global variable:
>>> whatever class[SIZE];

>>
>>I think you overlooked that in C++ class is an keyword, in C it isn't.
>>
>>so Legal c code:
>>int class = 42;
>>And illegal C++ code:
>>int class = 42;
>>
>>Yes there are things that C can do that C++ can't...

>
> So, in C, this is legal?
>
> int struct = 42;


You're absolutely right, I just typed in the OP's variable name on auto
pilot. Yeah, can't use any keyword as a var name (including struct).

So, no, int struct = 42; is not legal in c++


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
RE: keyword checker - keyword.kwlist Hamilton, William Python 4 05-13-2007 06:31 AM
keyword checker - keyword.kwlist tom@finland.com Python 6 05-10-2007 04:53 PM
jsp-api.jar and conflicting class after migration from jsf ==> MyFaces Ben Engbers Java 0 02-07-2007 12:11 PM
[ASP.NET 2.0] ChangePassword class conflicting with my page =?Utf-8?B?amF2YXRvcGlh?= ASP .Net 1 04-17-2006 04:14 PM
Nested Class, Member Class, Inner Class, Local Class, Anonymous Class E11 Java 1 10-12-2005 03:34 PM



Advertisments