Re: Macro redefinition
- From: Ben Pfaff <blp@xxxxxxxxxxxxxxx>
- Date: Fri, 31 Aug 2007 09:11:56 -0700
Tor Rustad <tor_rustad@xxxxxxxxxxx> writes:
void gen_source_function(FILE *out)
{
#define EXPAND_DEF(num, name) generate_source_1(out, num, #name)
#include "iso8583_defs"
#define EXPAND_DEF(num, name) generate_source_2(out, num, #name)
#include "iso8583_defs"
}
where the "iso8583_defs" file, did contain a lot of lines like this:
EXPAND_DEF(1, FIELD_NAME);
EXPAND_DEF(2, ANOTHER_FIELD_NAME);
My question is simply, is the above C code allowed?
Sure. Lots of code uses this trick to avoid redundancy.
If you don't like the idea of using an include file for this, you
can also use a macro:
void gen_source_function(FILE *out)
{
#define ISO8583_DEFS \
EXPAND_DEF(1, FIELD_NAME); \
EXPAND_DEF(2, ANOTHER_FIELD_NAME);
#define EXPAND_DEF(num, name) generate_source_1(out, num, #name)
ISO8583_DEFS
#define EXPAND_DEF(num, name) generate_source_2(out, num, #name)
ISO8583_DEFS
}
I think it's a toss-up which is better. Neither is pretty, both
are functional.
--
char a[]="\n .CJacehknorstu";int putchar(int);int main(void){unsigned long b[]
={0x67dffdff,0x9aa9aa6a,0xa77ffda9,0x7da6aa6a,0xa67f6aaa,0xaa9aa9f6,0x11f6},*p
=b,i=24;for(;p+=!*p;*p/=4)switch(0[p]&3)case 0:{return 0;for(p--;i--;i--)case+
2:{i++;if(i)break;else default:continue;if(0)case 1:putchar(a[i&15]);break;}}}
.
- Follow-Ups:
- Re: Macro redefinition
- From: Tor Rustad
- Re: Macro redefinition
- References:
- Macro redefinition
- From: Tor Rustad
- Macro redefinition
- Prev by Date: Re: C Offsetof
- Next by Date: Re: C Offsetof
- Previous by thread: Macro redefinition
- Next by thread: Re: Macro redefinition
- Index(es):
Relevant Pages
|