[splint-discuss] Parse Error on Macro, help

James Dennett jdennett at acm.org
Wed Sep 6 01:34:47 EDT 2006


Richard A. O'Keefe wrote:
> raymond <raymond-xu at 126.com> wrote:
> 	I write a simple C program with a Macro like below:
> 	
> 	/*test.c*/
> 	  1 #include<unistd.h>
> 	  2 #include<stdio.h>
> 	  3 #include <stdlib.h>
> 	  4 #define MSG_COMMON_HEADER()                     \
> 	  5         u_int16_t len;                          \
> ====>	  6         u_int16_t type;
>
> Note 1: having empty parentheses in a macro definition is technically
> undefined in C89.  (I'm not sure, it might be illegal.)
>   
Are you sure?  It's well-defined in C++98, which is almost identical to 
C89/90
in terms of preprocessing.  An empty parameter name is illegal, but the 
case of
() defines a function-like macro with no arguments.  AFAIK this is a
moderately common, strictly conforming, technique.
> Note 2: your macro ends with a ';'.
>
>   
Usually a bad idea, indeed.
> 	  7
> 	  8 struct any_msg {
> =====>	  9           MSG_COMMON_HEADER ();
>
> Note 3: having empty parentheses in a macro call is technically
> undefined in C89.  (I'm not sure, it might be illegal.)
>   
It's required to use a function-like macro with no arguments, I believe.
> In any case, putting argument parentheses on something which HAS
> no arguments and ISN'T intended to be function-like is, um, the
> very opposite of good style.  It confuses people.
>
> Note 4: your macro call has ANOTHER ';' after it.
>   
Which is bad style, at least.

-- James



More information about the splint-discuss mailing list