Operating System - HP-UX
1751687 Members
5606 Online
108781 Solutions
New Discussion юеВ

aCC difference between preprocessor and compiler

 
SOLVED
Go to solution
Gregory Kryltsov
Occasional Advisor

aCC difference between preprocessor and compiler

Version aCC A.03.56
Example:
file test.cpp
#--------------------------------------
#define A2U(x) L#x
int main(int argc, char* argv[])
{
wchar_t* p = A2U(TEST);
return 0;
}
#--------------------------------------

Run: aCC -P test.cpp
Preprocessor result (test.i):
#--------------------------------------
int main(int argc, char* argv[])
{
wchar_t* p = L"TEST" ;
return 0;
}
#--------------------------------------
No error if this result is compiling.

Run: aCC test.cpp
Result: 2 errors
#--------------------------------------
Error 172: "test.cpp", line 5 # Undeclared variable 'L'.
wchar_t* p = A2U(TEST);
^^^
Error 20: "test.cpp", line 5 # ';' expected before '"TEST"'.
wchar_t* p = A2U(TEST);
^^^
#--------------------------------------

It looks like the result of preprocessor and compiler is different. Can anybody help me to avoid this problem?

In previous aCC releases (3.27) there was problem in preprocessor also. For above example the result was

wchar_t* p = L тАЬTESTтАЭ ;
// There is 1 space symbol between L and тАЬTESTтАЭ.

Now the preprocessor is seems to be working correctly. What about compiler? Is that correct behav
15 REPLIES 15
MAUCCI_2
Frequent Advisor

Re: aCC difference between preprocessor and compiler

Greg,

aCC -P does NOT compile but only preprocesses...

What exactly do you want to do?

++Cyrille
Daavid Turnbull
Frequent Advisor

Re: aCC difference between preprocessor and compiler

You may find it useful to preprocess the source to a file. This will probably make it easier to determine what the compiler is complaining about.
Behold the turtle for he makes not progress unless he pokes his head out.
Gregory Kryltsov
Occasional Advisor

Re: aCC difference between preprocessor and compiler

That is what I'm talking about. The result of preprocessor differs from what compiler uses for compilation. When preprocessor gives correct result (the source code outputted by preprocessor is compiled successfully) compiler complains on some errors. The example: try to use L macro in define (see example above). Preprocessor outputs correct result where A2U(TEST) is converted to L"TEST". But compiler complains on "undeclared variable L". I noticed such problem when I started work with aCC 3.27. The preprocessor on this version outputs A2U(TEST) as L "TEST" (L plus SPACE plus "TEST"). And the error of "undeclared variable L" is obvious. So, I suppose this is not correct behavior. And it was fixed in preprocessor of 3.56 but not in compiler. My question is : is there any workaround to pass it over?
MAUCCI_2
Frequent Advisor

Re: aCC difference between preprocessor and compiler

Do you really believe this pre-processed code to be valid c++ code?

-Cyrille

int main(int argc, char* argv[])
{
wchar_t* p = L"TEST" ;
return 0;
}
MAUCCI_2
Frequent Advisor

Re: aCC difference between preprocessor and compiler

OK, I don't know if your code is valid or not, but I know see your point, and you may have expressed it this way to be more clear:


[08:37:57]:attend:/home/pack
cmaucci> aCC -E -.i a.cpp
[08:37:59]:attend:/home/pack
cmaucci> cat a.i
#line 1 "a.cpp"

#line 2 "a.cpp"
int main(int argc, char* argv[])
{
wchar_t* p = L"TEST" ;
return 0;
}
[08:38:03]:attend:/home/pack
cmaucci> aCC a.i
Warning 829: "a.cpp", line 4 # Implicit conversion of string literal to 'wchar_t *' is deprecated.
wchar_t* p = L"TEST" ;
^^^^^^^


IN 2 STEPS THIS HAS COMPILED!




[08:38:06]:attend:/home/pack
cmaucci> aCC a.cpp
Error 172: "a.cpp", line 4 # Undeclared variable 'L'.
wchar_t* p = A2U(TEST);
^^^
Error 20: "a.cpp", line 4 # ';' expected before '"TEST"'.
wchar_t* p = A2U(TEST);
^^^
[08:38:11]:attend:/home/pack
cmaucci>


IN 1 STEP THIS HAS NOT COMPILED


Gregory Kryltsov
Occasional Advisor

Re: aCC difference between preprocessor and compiler

Yes, this is some kind of workaround I tried to use but it doesn't work for me. Thank you anyway.
Stephen Keane
Honored Contributor

Re: aCC difference between preprocessor and compiler

What about the following slightly amended version?

#--------------------------------------
#define A2U(x) L ## #x
int main(int argc, char* argv[])
{
wchar_t* p = A2U(TEST);
return 0;
}
#--------------------------------------
Gregory Kryltsov
Occasional Advisor

Re: aCC difference between preprocessor and compiler

Stephen,

This example can not be compiled. Compiler returns 4 errors...
Also preprocessor returns result as
wchar_t* p = L#TEST ;
It seems like preprocessor can not make one more step - to substitute "TEST" instead of #TEST.
Stephen Keane
Honored Contributor
Solution

Re: aCC difference between preprocessor and compiler

I'm assuming that the '#--------' lines aren't actually in the C code?

If you are sure that the macro definition reads

#defineA2U(x)L###x

then your compiler is definitely wrong! There is nothing wrong with the syntax. I've checked it on 3 different compilers and they are all happy with it. Is your aCC patched to the latest level?

One kludge you might also try is:

#define CONCAT(x,y) x ## y
#define A2U(x) CONCAT(L,#x)

int main(int argc, char* argv[])
{
wchar_t* p = A2U(TEST);
return 0;
}

Worth a try!