Macro that Defines another on invocation

Discussion in 'C Programming' started by aravindh.k, Nov 22, 2005.

  1. aravindh.k

    aravindh.k Guest


    I want to define a macro that defines another on invocation. Somthing
    like this:

    #define MACRO_NR_1(FLAG, VALUE) #define MACRO_NR_1_##FLAG(VALUE)

    So that when I call MACRO_NR_1(10), the macro MACRO_NR_1_10 gets
    defined. The macro above does not work.

    Do you know how I may do this ?

    aravindh.k, Nov 22, 2005
    1. Advertisements

  2. # is, in fact, a pre-processor operator. It's operand should be one of the
    function-like macro's parameters, the 'value' of which will then be
    magically transformed into a string literal.

    So this is definitely not going to work.
    You may not. #3: "The resulting completely macro-replaced preprocessing token
    sequence is not processed as a preprocessing directive even if it
    resembles one."

    The "resulting completely macro-replaced preprocessing token sequence"
    being your fully processed macro replacement.
    Pieter Droogendijk, Nov 22, 2005
    1. Advertisements

  3. aravindh.k

    aravindh.k Guest

    dank u.

    I will not try it again. I plan to use inline functions now.
    Thanks for pasting the standard, now I know it cannot be done in ANSI C.
    aravindh.k, Nov 22, 2005
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.