Re: Macro redefinition



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;}}}
.



Relevant Pages

  • Re: compare two float values
    ... (either float or double) ... num = rand; ... num = atof(fgets(cNum, sizeof cNum, stdin)); ...
    (comp.lang.c)
  • Reset Occurs After Keyboard Interrupt on Motorola HC08
    ... interrupt, the chip resets itself. ... interrupt and clear interrupt masks (asm CLI). ... void lightOff(int num); ...
    (comp.arch.embedded)
  • Re: Ex 7-5
    ... int getop; ... double num; ... void clearStack; ... not make sense if the stack has been cleared so a fall-though can't ...
    (comp.lang.c)
  • Re: class question
    ... void CSetTextTestDlg::OnStart ... void CSetTextTestDlg::TextDisplay1(int num) ... void SetText::BeginText(CSetTextTestDlg* pDlg) ...
    (microsoft.public.vc.mfc)
  • Re: General rules on interface (function) design
    ... Your advices are welcome and appreciated. ... void itoa2(char *s, int num) ...
    (comp.lang.c)