warning C4002: too many actual parameters for macro 'assert'

This is a discussion on warning C4002: too many actual parameters for macro 'assert' within the C++ Programming forums, part of the General Programming Boards category; Hi, This compiles: Code: double a = cmath::euclideanDistance2D<BlasVector,double>(mTargetPosition, mrEntity.vehicleModel().pos()); assert(10.0 < a); But for this Code: assert(10.0 < cmath::euclideanDistance2D<BlasVector,double>(mTargetPosition, mrEntity.vehicleModel().pos())); ...

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    519

    warning C4002: too many actual parameters for macro 'assert'

    Hi,

    This compiles:

    Code:
    double a = cmath::euclideanDistance2D<BlasVector,double>(mTargetPosition, mrEntity.vehicleModel().pos());
    
    assert(10.0 < a);
    But for this

    Code:
    assert(10.0 < cmath::euclideanDistance2D<BlasVector,double>(mTargetPosition, mrEntity.vehicleModel().pos()));
    msvc gives these erros and warnings:

    Code:
    1>.\GoalMoveXY.cpp(46) : warning C4002: too many actual parameters for macro 'assert'
    1>.\GoalMoveXY.cpp(46) : error C2143: syntax error : missing ',' before ')'
    1>.\GoalMoveXY.cpp(46) : error C2059: syntax error : ')'
    1>.\GoalMoveXY.cpp(46) : error C2143: syntax error : missing ',' before ')'
    1>.\GoalMoveXY.cpp(46) : error C2059: syntax error : ')'
    1>.\GoalMoveXY.cpp(50) : error C2143: syntax error : missing ',' before ')'
    1>.\GoalMoveXY.cpp(53) : error C2065: 'way' : undeclared identifier
    1>.\GoalMoveXY.cpp(53) : error C2228: left of '.rend' must have class/struct/union
    1>        type is ''unknown-type''
    1>.\GoalMoveXY.cpp(53) : error C2143: syntax error : missing ',' before ')'
    1>.\GoalMoveXY.cpp(56) : error C2143: syntax error : missing ';' before '}'
    1>.\GoalMoveXY.cpp(60) : error C2143: syntax error : missing ';' before '{'
    1>.\GoalMoveXY.cpp(65) : error C2143: syntax error : missing ';' before '{'
    1>.\GoalMoveXY.cpp(68) : error C2143: syntax error : missing ';' before '}'
    1>.\GoalMoveXY.cpp(70) : error C2143: syntax error : missing ';' before '{'
    1>.\GoalMoveXY.cpp(71) : error C2143: syntax error : missing ',' before ')'
    1>.\GoalMoveXY.cpp(72) : error C2143: syntax error : missing ',' before ')'
    1>.\GoalMoveXY.cpp(81) : error C2143: syntax error : missing ';' before '{'
    1>.\GoalMoveXY.cpp(83) : error C2143: syntax error : missing ';' before '}'
    1>.\GoalMoveXY.cpp(84) : error C2143: syntax error : missing ';' before '}'
    1>.\GoalMoveXY.cpp(87) : error C2143: syntax error : missing ';' before '}'
    1>.\GoalMoveXY.cpp(90) : error C2143: syntax error : missing ';' before '}'
    1>.\GoalMoveXY.cpp(91) : error C2143: syntax error : missing ';' before '}'
    1>.\GoalMoveXY.cpp(91) : fatal error C1004: unexpected end-of-file found
    Arn't template parameters allowed inside macro calls?

    Thank you!

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    They probably are, but perhaps you need an extra set of paranthesis, as the preprocessor has no idea what a template is, and will just split arguments by commas.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    More precisely, it doesn't recognize < > as comma-masking. So yes, you need an extra pair of parenthesis.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by CornedBee View Post
    More precisely, it doesn't recognize < > as comma-masking. So yes, you need an extra pair of parenthesis.
    Yes, but the C preprocessor knows nothing ELSE about templates either, does it?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    But it doesn't need to know anything else. It's the commas that get you in trouble.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by CornedBee View Post
    But it doesn't need to know anything else. It's the commas that get you in trouble.
    You are right - there is no meaning to template that would matter to the preprocessor. I was trying (hard) to come up with some other obscure case where template "knowledge" would make a difference, but the only place which matters is commas in the <> section of templates.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  7. #7
    Registered User
    Join Date
    Jan 2007
    Posts
    330
    I guess the preprocessor sees it as:

    Code:
    assert(x < y < z,double>(mTargetPosition, mrEntity.vehicleModel().pos()));

  8. #8
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Yes, something like that. There are very few things in the syntax that matters to the preprocessor. It knows about whitespaces, comma, lparen '(' and rparen ')', the # sign, and that's about it. The rest of it is about text replacement of given parameters.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  9. #9
    Registered User
    Join Date
    Nov 2006
    Posts
    519
    Thank you all. Another pair of parenthesis did the trick.

  10. #10
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Strings. It knows about strings.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  11. #11
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by CornedBee View Post
    Strings. It knows about strings.
    Yes, of course. As in "somestuff", not std::strings

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  12. #12
    Registered User
    Join Date
    Jul 2009
    Posts
    1

    Lightbulb

    In case you want to "protect" a comma and parenthesis don't work (for example with templates), you can use the following macro:

    Code:
    #define CONCAT(...) __VA_ARGS__
    #define ID(x) x
    //...
    printf("%s %s!\n", ID(CONCAT("hello", "world")) );
    See more on my website...

    HTH,
    Ingo
    Last edited by CornedBee; 07-14-2009 at 08:15 AM.

  13. #13
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    4,261
    O_o

    Did you actually just search for questions to answer in order to advertise your site as a pathetic attempt to circumvent the rules?

    Anyway, this is the C++ forum--not the C99 forum.

    Soma

  14. #14
    C++11 User Tux0r's Avatar
    Join Date
    Nov 2008
    Location
    Sweden
    Posts
    135
    Quote Originally Posted by phantomotap View Post
    O_o

    Did you actually just search for questions to answer in order to advertise your site as a pathetic attempt to circumvent the rules?

    Anyway, this is the C++ forum--not the C99 forum.

    Soma
    lol my thought too

  15. #15
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Link deleted, thread closed. Don't resurrect old threads, especially in order to promote your site.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. pointers, structures, and malloc
    By lugnut in forum C Programming
    Replies: 24
    Last Post: 10-09-2008, 04:52 PM
  2. warning C4013...errrrrr!
    By IndioDoido in forum C Programming
    Replies: 27
    Last Post: 03-21-2008, 02:02 AM
  3. Script errors - bool unrecognized and struct issues
    By ulillillia in forum Windows Programming
    Replies: 10
    Last Post: 12-18-2006, 03:44 AM
  4. Replies: 2
    Last Post: 01-20-2004, 04:33 PM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21