Conflicting class keyword

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.

Advertisements

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.

Advertisements

"kiran kumr" <> wrote in message
news:...
> 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];

Jim Langston wrote:
> "kiran kumr" <> wrote in message
> news:...
> > 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.

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...

"BobR" <> wrote in message
news:0Lzph.691980$...
>
> 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).

Share This Page

Welcome to The Coding Forums!

Welcome to the Coding Forums, the place to chat about anything related to programming and coding languages.

Please join our friendly community by clicking the button below - it only takes a few seconds and is totally free. You'll be able to ask questions about coding or chat with the community and help others.
Sign up now!