C's Limited Macro Capabilities

Lawrence H. Miller lmiller at aerospace.aero.org
Tue Dec 5 06:54:31 AEST 1989


In article <69517 at psuecl.bitnet> bpm at psuecl.bitnet (Brian Moquin) writes:

	That he thinks macros like this would be useful:

>        #define cast(flag,x)    #if flag=='I' \
>                                        ((int)(x)) \
>                                #elif flag=='F' \
>                                        ((float)(x)) \
>                                #endif
>This is not legal C, but if it were I think it would enhance the power
>of macro expansions significantly.  Thoughts?


But for each such example, you can easily write a macro that
is legal.  Why not just have your macro do what you really
want, which is casting an expression to a type:

#define cast(type,x)		((type)(x))

Larry Miller



More information about the Comp.lang.c mailing list