kerravon <ke******@w3.towrote:
# According to 6.8 of C90, #if takes a constant expression.
#
# According to 6.4 of C90, the sizeof operator is part of a constant
# expression.
You conceptual have the stages
(1) preprocessor
(2) parser
(3) code generator
sizeof is a constant in third stage (code generator) which
comes after the preprocessor. You should not expect this kind
of backwards information flow from code generator to the
preprocessor.
One work around is write a small program that does the sizeof
and then writes an include file with appropriate defines.
# #if sizeof(int) >= 4
# #define XXX "big"
# #else
# #define XXX "small"
# #endif
For example, with make you can have something like
defineXXX.c :
#include <stdio.h>
int main(int N,char **P) {
if (sizeof(int)>=4)) puts("#define XXX \"big\"");
else puts("#define XXX \"small\"");
return 0;
}
main.c:
#include <stdio.h>
#include "XXX.h"
int main(void)
{
printf("hello %s\n", XXX);
return (0);
}
makefile:
main: main.c XXX.h
cc -o main main.c
XXX.h: defineXXX
defineXXX XXX.h
defineXXX: defineXXX.c
cc -o defineXXX defineXXX.c
--
SM Ryan
http://www.rawbw.com/~wyrmwif/
This is one wacky game show.