C Board  

Go Back   C Board > General Programming Boards > C++ Programming

Closed Thread
 
LinkBack Thread Tools Display Modes
Old 03-11-2008, 03:49 AM   #1
Registered User
 
Join Date: Nov 2006
Posts: 510
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!
pheres is offline  
Old 03-11-2008, 03:57 AM   #2
Kernel hacker
 
Join Date: Jul 2007
Location: Farncombe, Surrey, England
Posts: 15,686
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.
matsp is offline  
Old 03-11-2008, 04:08 AM   #3
Cat without Hat
 
CornedBee's Avatar
 
Join Date: Apr 2003
Posts: 8,579
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
CornedBee is online now  
Old 03-11-2008, 04:13 AM   #4
Kernel hacker
 
Join Date: Jul 2007
Location: Farncombe, Surrey, England
Posts: 15,686
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.
matsp is offline  
Old 03-11-2008, 04:23 AM   #5
Cat without Hat
 
CornedBee's Avatar
 
Join Date: Apr 2003
Posts: 8,579
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
CornedBee is online now  
Old 03-11-2008, 04:39 AM   #6
Kernel hacker
 
Join Date: Jul 2007
Location: Farncombe, Surrey, England
Posts: 15,686
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.
matsp is offline  
Old 03-11-2008, 04:42 AM   #7
Registered User
 
Join Date: Jan 2007
Posts: 250
I guess the preprocessor sees it as:

Code:
assert(x < y < z,double>(mTargetPosition, mrEntity.vehicleModel().pos()));
KIBO is offline  
Old 03-11-2008, 04:48 AM   #8
Kernel hacker
 
Join Date: Jul 2007
Location: Farncombe, Surrey, England
Posts: 15,686
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.
matsp is offline  
Old 03-11-2008, 06:28 AM   #9
Registered User
 
Join Date: Nov 2006
Posts: 510
Thank you all. Another pair of parenthesis did the trick.
pheres is offline  
Old 03-11-2008, 08:25 AM   #10
Cat without Hat
 
CornedBee's Avatar
 
Join Date: Apr 2003
Posts: 8,579
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
CornedBee is online now  
Old 03-11-2008, 08:27 AM   #11
Kernel hacker
 
Join Date: Jul 2007
Location: Farncombe, Surrey, England
Posts: 15,686
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.
matsp is offline  
Old 07-14-2009, 06:34 AM   #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.
ingomueller.net is offline  
Old 07-14-2009, 06:42 AM   #13
Registered User
 
phantomotap's Avatar
 
Join Date: Jan 2008
Posts: 920
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
phantomotap is offline  
Old 07-14-2009, 06:44 AM   #14
C++0x User
 
Tux0r's Avatar
 
Join Date: Nov 2008
Location: Sweden
Posts: 133
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
Tux0r is offline  
Old 07-14-2009, 08:16 AM   #15
Cat without Hat
 
CornedBee's Avatar
 
Join Date: Apr 2003
Posts: 8,579
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
CornedBee is online now  
Closed Thread

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
pointers, structures, and malloc lugnut C Programming 24 10-09-2008 04:52 PM
warning C4013...errrrrr! IndioDoido C Programming 27 03-21-2008 02:02 AM
Script errors - bool unrecognized and struct issues ulillillia Windows Programming 10 12-18-2006 04:44 AM
warning C4003: not enough actual parameters for macro 'min' Magos C++ Programming 2 01-20-2004 05:33 PM
Interface Question smog890 C Programming 11 06-03-2002 05:06 PM


All times are GMT -6. The time now is 12:18 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

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