a question on c++ preprocessor

X

xin1wang1

I have just checked the faq and some refs on my bookshelf, but fail to
find an answer to my following question:

I am developing a code generator which generates c++ code from some
interface definitions (xml) .... The generated code needs to be
compiled against some other manully written code. If some prototype
mis-match between the generated code and the manul code, I would like
the compiler to report the problem by pointing out the location of the
problematic interface definition in the xml file, rather than reporting
error (prototype mismatch) pointing to the generated c++ file.

I guess I can do this by inserting

# <line> "<text>" <list of numbers>

in the generating C++ code. This causes the c++ compiler to report the
error as:

<text>:<line+delta> ....

My questions are:

1. whether this is portable, as I don't want the geneated code to be
platform dependent.
2. what is the <list of numbers>'s standard format and usefulness?
 
G

Greg

I have just checked the faq and some refs on my bookshelf, but fail to
find an answer to my following question:

I am developing a code generator which generates c++ code from some
interface definitions (xml) .... The generated code needs to be
compiled against some other manully written code. If some prototype
mis-match between the generated code and the manul code, I would like
the compiler to report the problem by pointing out the location of the
problematic interface definition in the xml file, rather than reporting
error (prototype mismatch) pointing to the generated c++ file.

I guess I can do this by inserting

# <line> "<text>" <list of numbers>

No, the supported syntax for the #line directive is:

#line <digit-sequence> "<s-char-sequence>"

The digit-sequence specifies the new line number (which is stored in
the predefined macro: __LINE__). The optional char-sequence within
quotes specifies the new source file name (which is kept in the
predefined macro: __FILE__).
My questions are:

1. whether this is portable, as I don't want the geneated code to be
platform dependent.

The #line directive has been part of C++ and C since well before either
language was a standard. So I can't imagine any likely portability
issues with its use.
2. what is the <list of numbers>'s standard format and usefulness?

See above or refer to §16.4 of the C++ Standard for the syntax of a
#line directive. Note that it is legal to use macros in a #line
directive just as long as the result of their expansiion is a valid
#line directive shown above - otherwise the behavior of the #line
directive is formally, undefined.

Greg
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top