Hi,
I don't understand why the first C (c, not c++) program compiles and the second one does not compile.
Any idea what is happening with the macro pre-processor in here, why StateStart(0) can be used in the printf statement, but not in the #define?
TIA & Regards ...
First version: compiles
[code=c]#include <stdio.h>
#define FIRST 4
#define StateStart(n) (STATE##n##_STA RT)
#define STATE0_START (FIRST)
#define STATE1_START (STATE0_START+5 )
main()
{
printf("State 0 start: %d\n", STATE0_START);
printf("State 1 start: %d\n", STATE1_START);
printf("State 0 start: %d\n", StateStart(0));
printf("State 1 start: %d\n", StateStart(1));
}
[/code]
Second Version: Does not compile
Error: warning C4013: 'StateStart' undefined; assuming extern returning int
[code=c]
#include <stdio.h>
#define FIRST 4
#define StateStart(n) (STATE##n##_STA RT)
#define STATE0_START (FIRST)
#define STATE1_START (StateStart(0)+ 5)
main()
{
printf("State 0 start: %d\n", STATE0_START);
printf("State 1 start: %d\n", STATE1_START);
printf("State 0 start: %d\n", StateStart(0));
printf("State 1 start: %d\n", StateStart(1));
}[/code]
I don't understand why the first C (c, not c++) program compiles and the second one does not compile.
Any idea what is happening with the macro pre-processor in here, why StateStart(0) can be used in the printf statement, but not in the #define?
TIA & Regards ...
First version: compiles
[code=c]#include <stdio.h>
#define FIRST 4
#define StateStart(n) (STATE##n##_STA RT)
#define STATE0_START (FIRST)
#define STATE1_START (STATE0_START+5 )
main()
{
printf("State 0 start: %d\n", STATE0_START);
printf("State 1 start: %d\n", STATE1_START);
printf("State 0 start: %d\n", StateStart(0));
printf("State 1 start: %d\n", StateStart(1));
}
[/code]
Second Version: Does not compile
Error: warning C4013: 'StateStart' undefined; assuming extern returning int
[code=c]
#include <stdio.h>
#define FIRST 4
#define StateStart(n) (STATE##n##_STA RT)
#define STATE0_START (FIRST)
#define STATE1_START (StateStart(0)+ 5)
main()
{
printf("State 0 start: %d\n", STATE0_START);
printf("State 1 start: %d\n", STATE1_START);
printf("State 0 start: %d\n", StateStart(0));
printf("State 1 start: %d\n", StateStart(1));
}[/code]
Comment