macro in macro ... in macro aber wie?



  • Guten abend, 🤡

    folgentes ich habe sowas

    #define DEFINITION_CGRAF(KnoteVar, EdgeVar)\
    	DEFINITION_CGRAFSTRUCT(KnoteVar, EdgeVar);\
    	DEFINITION_CGRAFBASIC(KnoteVar, EdgeVar);\
    	DEFINITION_CGRAFADVANCE(KnoteVar, EdgeVar);
    DEFINITION_CGRAF(char, char);
    
    //So wie hier steht funktioniert es einbanfrei
    

    wobei DEFINITION_CGRAFSTRUCT, DEFINITION_CGRAFBASIC, DEFINITION_CGRAFADVANCE
    auch macros jetzt will ich so was machen

    #define DEFINITION_CGRAF(KnoteVar, EdgeVar)\
    ###ifndef DEFINITION_CGRAF_##KnoteVar##_##EdgeVar####\
    ###define DEFINITION_CGRAF_##KnoteVar##_##EdgeVar####\
    	DEFINITION_CGRAFSTRUCT(KnoteVar, EdgeVar);\
    	DEFINITION_CGRAFBASIC(KnoteVar, EdgeVar);\
    	DEFINITION_CGRAFADVANCE(KnoteVar, EdgeVar);\
    ###endif##
    
    //Hier funktioniert nicht
    

    Damit ich ausfersen in mein surce code nicht 2 mal DEFINITION_CGRAF(char, char); definire so halt wie include protection aber der kompiler schlukt das nicht, kann mir einer weiter helfen.

    fehler in MS VC++ 6.0

    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(51) : error C2160: '##' cannot occur at the beginning of a macro definition
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(51) : error C2160: '##' cannot occur at the beginning of a macro definition
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(51) : error C2162: expected macro formal parameter
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(52) : error C2162: expected macro formal parameter
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(56) : error C2162: expected macro formal parameter
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2061: syntax error : identifier 'DEFINITION_CGRAF_KnoteVar_chardefine'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2059: syntax error : ';'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2143: syntax error : missing '{' before '*'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2143: syntax error : missing ')' before '*'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2143: syntax error : missing '{' before '*'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2059: syntax error : ')'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2054: expected '(' to follow 'In'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2143: syntax error : missing ')' before '*'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2143: syntax error : missing '{' before '*'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2146: syntax error : missing ';' before identifier 'End'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2059: syntax error : ')'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2054: expected '(' to follow 'End'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2143: syntax error : missing '{' before '*'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2143: syntax error : missing ')' before '*'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2143: syntax error : missing '{' before '*'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2059: syntax error : ')'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2054: expected '(' to follow 'In'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2143: syntax error : missing ')' before '*'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2143: syntax error : missing '{' before '*'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2146: syntax error : missing ';' before identifier 'NewEdge'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2059: syntax error : ')'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2054: expected '(' to follow 'NewEdge'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2146: syntax error : missing ')' before identifier 'EdgeIn'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2061: syntax error : identifier 'EdgeIn'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2059: syntax error : ';'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2059: syntax error : ')'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2449: found '{' at file scope (missing function header?)
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2059: syntax error : '}'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2146: syntax error : missing ')' before identifier 'In'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2061: syntax error : identifier 'In'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2059: syntax error : ';'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2059: syntax error : ')'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2449: found '{' at file scope (missing function header?)
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2059: syntax error : '}'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2143: syntax error : missing '{' before '*'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2143: syntax error : missing ')' before '*'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2143: syntax error : missing '{' before '*'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2059: syntax error : ')'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2054: expected '(' to follow 'GrafIn'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2143: syntax error : missing ')' before '*'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2143: syntax error : missing '{' before '*'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2146: syntax error : missing ';' before identifier 'NextIn'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2059: syntax error : ')'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2054: expected '(' to follow 'NextIn'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2143: syntax error : missing ')' before '*'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2143: syntax error : missing '{' before '*'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2146: syntax error : missing ';' before identifier 'HeadIn'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2059: syntax error : ')'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2054: expected '(' to follow 'HeadIn'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2143: syntax error : missing ')' before '*'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2143: syntax error : missing '{' before '*'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2059: syntax error : 'type'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2059: syntax error : ')'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2143: syntax error : missing ')' before '*'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2143: syntax error : missing '{' before '*'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2059: syntax error : ')'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2054: expected '(' to follow 'GrafIn'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2146: syntax error : missing ')' before identifier 'In'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2061: syntax error : identifier 'In'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2059: syntax error : ';'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2059: syntax error : ')'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2449: found '{' at file scope (missing function header?)
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2059: syntax error : '}'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2146: syntax error : missing ')' before identifier 'G'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2061: syntax error : identifier 'G'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2059: syntax error : ';'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2059: syntax error : ')'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2449: found '{' at file scope (missing function header?)
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2059: syntax error : '}'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2143: syntax error : missing '{' before '*'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2146: syntax error : missing ')' before identifier 'GrafIn'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2061: syntax error : identifier 'GrafIn'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2059: syntax error : ';'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2059: syntax error : ','
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2059: syntax error : ')'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2143: syntax error : missing ')' before '*'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2143: syntax error : missing '{' before '*'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2059: syntax error : ')'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2054: expected '(' to follow 'p'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2143: syntax error : missing ')' before '*'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2143: syntax error : missing '{' before '*'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2146: syntax error : missing ';' before identifier 'p'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2040: 'p' : 'int ' differs in levels of indirection from 'int *'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2146: syntax error : missing ';' before identifier 'q'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2059: syntax error : ')'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2054: expected '(' to follow 'q'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2143: syntax error : missing ')' before '*'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2143: syntax error : missing '{' before '*'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2146: syntax error : missing ';' before identifier 'p'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2059: syntax error : ')'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2040: 'p' : 'int ' differs in levels of indirection from 'int *'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2054: expected '(' to follow 'p'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2143: syntax error : missing ')' before '*'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2143: syntax error : missing '{' before '*'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2146: syntax error : missing ';' before identifier 'p'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : error C2059: syntax error : ')'
    o:\my data\myfunktion\ctemplates\pointedgraf\grafincludes\standartgraf\standartgraf.h(58) : fatal error C1003: error count exceeds 100; stopping compilation
    Error executing cl.exe.
    
    Main.exe - 102 error(s), 0 warning(s)
    

    Danke in voraus



  • man kann schlicht keine präprozessor-direktiven in makros setzten.

    für dein problem gibt es glaub ich keine lösung. dir bleibt nichts anderes, als darauf zu hoffen, daß der compiler/linker bei mehr als einer definition einen fehler meldet. du könntest höchstens in DEFINITION_CGRAF einen "dummy-typ" deklarieren. bei mehrmaligen aufruf würde der compiler dann einen fehler melden:

    #define DEFINITION_CGRAF(KnoteVar, EdgeVar)        \
            typedef int _DEFINITION_CGRAF;             \
            DEFINITION_CGRAFSTRUCT(KnoteVar, EdgeVar); \
            DEFINITION_CGRAFBASIC(KnoteVar, EdgeVar);  \
            DEFINITION_CGRAFADVANCE(KnoteVar, EdgeVar)
    

    das letzte semikolon im makro solltest du übrigens weglassen, weil sonst beim aufruf von

    DEFINITION_CGRAF(char, char);
    

    zwei semikolons hintereinander stünden. das kann bei c-compilern (im gegensatzt zu c++-compilern) zu einem fehler führen



  • Ooooooooooooooooooooooooohhhhhhhhhh kake das was ich bin tot. 😕

    P.S. Danke fur den tip mit den semicolon!!!!!!!!!!!!!!!!!!!


Anmelden zum Antworten