compilation error with CC

R

Rahul

Hi Everyone,

I have the following files,


file.h

typedef struct
{
int data;
#if (MACRO == 1)
int net_data;
#endif
} Object;


file1.cpp

#include "file.h"
uses object.data and object.net_data (under MACRO cc)

file2.cpp

#include "file.h"
uses object.data and object.net_data (under MACRO cc)



When i compile the file1.cpp it compiles fine without any errors,
however the file2.cpp gives an error saying

"C2363E: member net_data not found in struct object"

Note that the macro is set to 1 before compilation of these two
files... I'm not able to figure out as to why the file.h is expanded
(with MACRO as 0) and file2.cpp is expanded (with MACRO as 0)...

Has anyone faced similar situation? I have no clue as to how to fix
the problem?

Thanks in advance !!!
 
R

Rahul

What is "cc"? Once you figure it out, post to the newsgroup that
deals with it, because your question is apparently compiler-specific.

If instead of defining your macro (and, BTW, did you give it the value
'1' at that time?) in the command line (seems that's what you did) you
define it like so:

------- file2.cpp
#define MACRO 1
#include "file.h"
...

, does it work then? If it does, and in the command line it does not,
you got the _usage_ issue, not a language issue.

V

I meant, Conditional compilation by cc... I posted in here, as c++
developers over here might have faced this issue...
 
R

Rahul

Uh... How to break it to ya... There are _literally_ scores of
different compilers out there. "C++ developers over here" use all
of them. Half of those compilers have their main module named 'cc'
(or something very close). Which ones did you intend to reach with
your post? Once again, your issue is not of the _langauge_ kind
but relates to the _usage of your compiler_. Ask in the newsgroup
that *deals with your particular compiler*. If you are unsure what
newsgroup to post to, at least state the platform you're using and
the version of your compiler, then we can suggest a particular NG
for you. And RTFFAQ before posting as well.

V

Wish i could specify the details, but can't...

Anyways, does the standard say anything about the order in which pre-
processor works?
Does it evaluate conditional compilation first and then perform file
inclusion or the other way around?
 
T

tragomaskhalos

Hi Everyone,

 I have the following files,

 file.h

 typedef struct
 {
  int data;
#if (MACRO == 1)
  int net_data;
#endif
 } Object;

 file1.cpp

#include "file.h"
uses object.data and object.net_data (under MACRO cc)

 file2.cpp

#include "file.h"
uses object.data and object.net_data (under MACRO cc)

 When i compile the file1.cpp it compiles fine without any errors,
however the file2.cpp gives an error saying

 "C2363E: member net_data not found in struct object"

 Note that the macro is set to 1 before compilation of these two
files... I'm not able to figure out as to why the file.h is expanded
(with MACRO as 0) and file2.cpp is expanded (with MACRO as 0)...

  Has anyone faced similar situation? I have no clue as to how to fix
the problem?

Your compiler will most likely have an option to dump the
preprocessor output to a file (it's -P or -E for MSVC I think);
find out what it is for your compiler, compile using said option
and have a look at the files produced. This should give you
a clue as to what's going on.
 
J

James Kanze

[...]
Uh... How to break it to ya... There are _literally_ scores
of different compilers out there. "C++ developers over here"
use all of them. Half of those compilers have their main
module named 'cc' (or something very close).

Actually, I don't know of any C++ compilers that are invoked by
cc: I've got CC, g++ and cl here, with xlC and acc on some
machines I've used in the past. Under Unix, cc is classically
used to invoke the C compiler, so can't be the C++ compiler.

(As for the rest, of course... We need a minimum compilable
example. I don't know of any compiler that just randomly
defines macros, so obviously, it's being defined somewhere.
Also, of course, using conditional compilation to change the
layout of a structure is just looking for trouble. And is
totally unmaintainable.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,739
Latest member
Clint8040

Latest Threads

Top