Path: utzoo!attcan!uunet!cs.utexas.edu!samsung!uakari.primate.wisc.edu!uflorida!novavax!twwells!bill From: bill@twwells.com (T. William Wells) Newsgroups: comp.lang.c Subject: Re: C's Limited Macro Capabilities Message-ID: <1989Dec4.033809.16802@twwells.com> Date: 4 Dec 89 03:38:09 GMT References: <69517@psuecl.bitnet> Organization: None, Ft. Lauderdale, FL Lines: 26 In article <69517@psuecl.bitnet> bpm@psuecl.bitnet (Brian Moquin) writes: : A student in my C class asked me an interesting question: can you have : conditional compilation directives embedded within '#define' macros? : The answer is no. The student pointed out that this then : severely limits the macro capabilities of C. He said that in assembler : (MASM, I'm sure), he can write macros which contain arguments that : determine how the macros get expanded. I had trouble coming up with : a good analogous example in C, but here's one to think about: : #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? This particular one can be dealt with in ANSI C, I think. Something like: #define cast_F(x) ((float)(x)) #define cast_I(x) ((int)(x)) #define cast(flag,x) cast_##flag((x)) --- Bill { uunet | novavax | ankh | sunvice } !twwells!bill bill@twwells.com