Re: Macro redefinition
- From: Tor Rustad <tor_rustad@xxxxxxxxxxx>
- Date: Fri, 31 Aug 2007 20:52:48 +0200
Ben Pfaff wrote:
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.
Yup, that's the idea.
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
}
Interesting, I haven't seen this solution before.
However, there is a translation limit of "509 characters in a logical source line", and isn't logical source lines made up after line-splicing your ISO8583_DEFS above?
--
Tor <torust [at] online [dot] no>
.
- Follow-Ups:
- Re: Macro redefinition
- From: Ben Pfaff
- Re: Macro redefinition
- References:
- Macro redefinition
- From: Tor Rustad
- Re: Macro redefinition
- From: Ben Pfaff
- Macro redefinition
- Prev by Date: Re: How to force fscanf to find only data on a single input line?
- Next by Date: Re: Macro redefinition
- Previous by thread: Re: Macro redefinition
- Next by thread: Re: Macro redefinition
- Index(es):