Okay, I am in the office now and have had the chance to play with it a little.
Code:
#include <stdio.h>
#define MMM_P(x)_C(z) (0x0C + (((x)-1)*3 + ((z)-1))*4)
#define OFFSET (0xF0000 + 0xe800)
int main()
{
int i;
int j;
unsigned int x;
for (i=1; i<6; i++)
{
for (j=1; j<4; j++)
{
x = OFFSET + MMM_P(i)_C(j);
printf("Port %i Register %i addr : %08X\n", i,j,x);
}
printf("\n");
}
return 0;
}
This program, with the odd looking macro construction does not compile. I get the following errors from gcc...
Code:
junk2.c: In function ‘main’:
junk2.c:15: error: ‘z’ undeclared (first use in this function)
junk2.c:15: error: (Each undeclared identifier is reported only once
junk2.c:15: error: for each function it appears in.)
junk2.c:15: error: called object ‘_C(<erroneous-expression>)’ is not a function
junk2.c:15: error: expected ‘;’ before ‘_C’
This program, with a more traditional looking macro definition does compile...
Code:
#include <stdio.h>
#define MMM_P_C(x,z) (0x0C + (((x)-1)*3 + ((z)-1))*4)
#define OFFSET (0xF0000 + 0xe800)
int main()
{
int i;
int j;
unsigned int x;
for (i=1; i<6; i++)
{
for (j=1; j<4; j++)
{
x = OFFSET + MMM_P_C(i,j);
printf("Port %i Register %i addr : %08X\n", i,j,x);
}
printf("\n");
}
return 0;
}
... and gives the expected output.
Code:
Port 1 Register 1 addr : 000FE80C
Port 1 Register 2 addr : 000FE810
Port 1 Register 3 addr : 000FE814
Port 2 Register 1 addr : 000FE818
Port 2 Register 2 addr : 000FE81C
Port 2 Register 3 addr : 000FE820
Port 3 Register 1 addr : 000FE824
Port 3 Register 2 addr : 000FE828
Port 3 Register 3 addr : 000FE82C
Port 4 Register 1 addr : 000FE830
Port 4 Register 2 addr : 000FE834
Port 4 Register 3 addr : 000FE838
Port 5 Register 1 addr : 000FE83C
Port 5 Register 2 addr : 000FE840
Port 5 Register 3 addr : 000FE844
The strange macro construct does not prevent the program compiling if it is not used.
Well, there you go.