kb5mu@pnet01.CTS.COM (06/07/87)
I still haven't bought Turbo C, but a friend reports a preprocessor
bug. This code:
#define ctrl(x) (x & 037)
printf("ctrl(d) = %d\n", ctrl('d'));
expands to:
printf("ctrl(d) = %d\n", (ctrl & 037));
instead of the correct:
printf("ctrl(d) = %d\n", ('d' & 037));
This happens with all flavors of the compiler, including the
preprocessor-only version.
[This is an ANSI-compatible version of the more traditional
#define ctrl(x) ('x' & 037)
printf("ctrl(d) = %d\n", ctrl(d));
The traditional form doesn't work either.]
Paul Williamson
... sdcsvax!crash!pnet01!kb5mu
or ... williams@macomw.arpamarkg@amd.UUCP (06/08/87)
In article <7729@brl-adm.ARPA> kb5mu@pnet01.CTS.COM (Paul Williamson) writes:
- a friend reports a preprocessor bug. This code:
- #define ctrl(x) (x & 037)
- printf("ctrl(d) = %d\n", ctrl('d'));
-expands to:
- printf("ctrl(d) = %d\n", (ctrl & 037));
-instead of the correct:
- printf("ctrl(d) = %d\n", ('d' & 037));
This is only a bug in the CPP.EXE program. TCC.EXE does not use this pre-
processor.
-This happens with all flavors of the compiler, including the
-preprocessor-only version.
I attempted to reproduce the same problem using TCC/TC.EXE. The program
compiled and executed correctly. Using your example, the program printed 4.
Sorry to say that TCC.EXE can't produce a preprocessor pass output file so
we could see what really happens, but you can look at the .ASM file.
--
Mark Gorlinsky - AMD Processor Products Division/APPS SQA
UUCP: {decwrl,ihnp4,allegra}!amd!markg
AT&T: (408) 982-7811
DISCLAIMER: My opinions are mine, not my employers.