Operating System - HP-UX
1828976 Members
2227 Online
109986 Solutions
New Discussion

#define multiline problem - hpux newbie

 
Steve Colbert
Occasional Contributor

#define multiline problem - hpux newbie

Hello,

am using the aCC compiler (A.03.27) to port code originally from sun to hpux. Am getting errors for a #define statement that has multiple lines. The following code snippet generates compiler errors.

#define ErrorIntercept() catch (Error &__e__) { __e__.Report(); throw; }catch(std::bad_alloc&) { Error __e__(Error::OUT_OF_MEMORY); __e__.Report(); throw; } catch(...) { Error __e__(Error::EXCEPTION); __e__.Report(); throw; }

And here are the compiler errors

Error 19: "Error.h", line 171 # Unexpected 'catch'.
catch (Error &__e__) ^^^^^
Error 92: "Error.h", line 171 # Character '\' (value 92) was unexpected.
catch (Error &__e__) ^
Error 19: "Error.h", line 171 # Unexpected 'Error'.
catch (Error &__e__) ^^^^^
Error 92: "Error.h", line 172 # Character '\' (value 92) was unexpected.
{ ^
Error 24: "Error.h", line 172 # '[' expected instead of '{'.
{ ^
Error 92: "Error.h", line 173 # Character '\' (value 92) was unexpected.
__e__.Report(); ^
Error 24: "Error.h", line 173 # '(' expected instead of ';'.
__e__.Report(); ^
Error 92: "Error.h", line 174 # Character '\' (value 92) was unexpected.
throw; ^
Error 22: "Error.h", line 174 # Syntax error.
throw; ^
Error 92: "Error.h", line 175 # Character '\' (value 92) was unexpected.
} catch(std::bad_alloc&) ^
Error 92: "Error.h", line 176 # Character '\' (value 92) was unexpected.
{ ^
Error 92: "Error.h", line 177 # Character '\' (value 92) was unexpected.
Error __e__(Error::OUT_OF_MEMORY);


If I put the entire code snippet on one line it compiles without a hitch. Any help please?

3 REPLIES 3
A. Clay Stephenson
Acclaimed Contributor

Re: #define multiline problem - hpux newbie

Hi Steve,

Sorry, the aCC preprocessor documentation clearly states that macros cannot span lines.
However, you can use the "/" (Which must be the last character on the line) as a continuation.

e.g.
#define swap(a,b,temp) { temp = a; a = b; b = temp; }

You are the victim of a feature.
Regards, Clay
If it ain't broke, I can fix that.
A. Clay Stephenson
Acclaimed Contributor

Re: #define multiline problem - hpux newbie

Hi Steve, after looking at my reply, I noticed that my response lacked the backslashes though I did insert them. It's possible your original posting suffered the same fate. I did try using the backslashs on an aCC preprocess and it worked just fine.

Clay
If it ain't broke, I can fix that.
Steve Colbert
Occasional Contributor

Re: #define multiline problem - hpux newbie

Clay,

I tried your forward slash continuation character for my code and still no luck. I looked at the 3.27 doc and found the following:

"NOTE: The replacement-list must fit on one line. If the line becomes too long, it can be broken up into several lines provided that all lines but the last are terminated by a "\" character. The following is an example.


#define mac very very longreplacement string

The "\" must be the last character on the line. You cannot add any spaces or comments after it."

Notice that the doc says to use a backslash. Neither convention works for me. If I look at the standard includes, I see backslash continuation characters used throughout. Is there a compiler switch that I need to implement this behavior? My current settings are "-c +z +p -AA +DAportable +DD32 -DHPUX -D_REENTRANT -D_THREAD_SAFE -D_POSIX_C_SOURCE=199506L -D_HPUX_SOURCE -D_RWSTD_MULTI_THREAD -D_RWSTD_TEMPLATE"

Thanks for all your help...