Pre-compiler doesn't replace macro inside a template code

Hello,

I have a strange problem while using MACRO inside template class/method.

The pre-compiler doesn't sreplace the macro inside the code, but leave it without changes.

So this code failed to compile, and I have no solution unless I will replace it by myself !!!

Is this a wrong/correct behavior ?

My environment is: Solaris 10 with C++ SunStudio 11.

Thanks for any tips.

[417 byte] By [jberkovitch] at [2007-11-26 10:15:57]
# 1
Could you provide any example?
Atanasyan at 2007-7-7 2:08:52 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 2

Sorry but the problem is not as I described.

In our application, the problem is that the include files are not opened, or to be more precise they are not opened/spread in the order they appear.

We have several include file but each time they appear they are not opened.

It seems that I don't understand the pre-compiler rules about expending the include file.

So I got the error about the macro because the include file is expended later on. We have the same problem with sone class definitions.

So my problem is related to include file that are not expended in the order they appear in the header file.

Thanks.

jberkovitch at 2007-7-7 2:08:52 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 3

Usually content of header file is surrounded by #ifndef/#endif pragmas to prevent multiple inclusion:

[code]

// file a.h

#ifndef _A_H

#define _A_H

// content is here

#endif

[/code]

So if you have something like test cases below content of file b.h will be expanded in the file t.cc before content of file a.h:

[code]

// file a.h

#ifndef _A_H

#define _A_H

#include "b.h"

// some declarations here

#endif

[/code]

[code]

// file b.h

#ifndef _B_H

#define _B_H

// some declarations here

#endif

[/code]

[code]

// file t.cc

#include "a.h"

#include "b.h"

// code is here

[/code]

Maybe this is your case.

Atanasyan at 2007-7-7 2:08:52 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 4

Thanks for your help.

For sure I surrounded all the header file with ifndef...define...endif, and I re-checked and there are no errors like you described.

Also I used the option -E to see the file after pre-compilation, and I can see that some basic definitions are included after their usage, even if the header file was placed before.

It seems that there is a reason for the compiler to not expand the header file for some reason.

Is the usage of template could be the reason ? Or the compiler looks for instantiation and then expand the header file ?

Thanks for your hlep.

jberkovitch at 2007-7-7 2:08:52 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 5
Any test case shows the problem would be helpful.1. Is this problem related to system headers?2. Are template declarations and template definitions in the different files?
Atanasyan at 2007-7-7 2:08:52 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 6

The problem occurred with our header files and not system header files.

It's will be difficult to provide you some exmaple, or it will take us a lot of time, because it's currently occurred in our application that have a big number of files.

But if you don't see any other way to help us, I will provide some part of our sources.

Thanks for your time.

Regards.

jberkovitch at 2007-7-7 2:08:52 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 7
my guess is you've got two header files that check for (and maybe define) the same macro as inclusion guards. probably a copy and paste error./lib
slashlib at 2007-7-7 2:08:52 > top of Java-index,Development Tools,Solaris and Linux Development Tools...