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, 5 1282
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.
"kiran kumr" <ki***************@hp.comwrote in message
news:45******@usenet01.boi.hp.com...
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" <ki***************@hp.comwrote in message
news:45******@usenet01.boi.hp.com...
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...
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
"BobR" <Re***********@worldnet.att.netwrote in message
news:0L*********************@bgtnsc04-news.ops.worldnet.att.net...
>
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++ This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Cody Powell |
last post by:
I have a partial class split across two files. In the class
declaration found in the first file, I state that it's a sealed class.
In the class declaration found in the second file, I do not use...
|
by: Neo Geshel |
last post by:
I am having conflicting results with two pieces of identical code. One
is an insert, the other is an update to a db.
The first code, which works, is this:
Sub Add3_Click(sender As Object, e As...
|
by: Neo Geshel |
last post by:
I am having conflicting results with two pieces of identical code. One
is an insert, the other is an update to a db.
The first code, which works, is this:
Sub Add3_Click(sender As Object, e As...
|
by: dickinsm |
last post by:
Here's an example of a problem that I've recently come up against for
the umpteenth time. It's not difficult to solve, but my previous
solutions have never seemed quite right, so I'm writing to...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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...
|
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...
|
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...
| |