a question on c++ preprocessor

Discussion in 'C++' started by xin1wang1@yahoo.com, Nov 5, 2006.

  1. Guest

    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?
    , Nov 5, 2006
    #1
    1. Advertising

  2. Greg Guest

    wrote:
    > 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
    Greg, Nov 5, 2006
    #2
    1. Advertising

  3. Chris Thomasson, Nov 5, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dan W.
    Replies:
    9
    Views:
    325
    Paul Mensonides
    Dec 4, 2003
  2. xuatla
    Replies:
    1
    Views:
    354
    Denis Remezov
    Jul 10, 2004
  3. Cronus
    Replies:
    1
    Views:
    645
    Paul Mensonides
    Jul 15, 2004
  4. ³á³á³á³á

    Preprocessor's question

    ³á³á³á³á, Sep 12, 2003, in forum: C Programming
    Replies:
    1
    Views:
    323
    Martin Ambuhl
    Sep 12, 2003
  5. Neil Zanella

    preprocessor question

    Neil Zanella, Nov 6, 2003, in forum: C Programming
    Replies:
    4
    Views:
    314
    Eric Sosman
    Nov 6, 2003
Loading...

Share This Page