Post by Ben Bacarisse Post by David Kleinecke
Would there be any downside were I to realize character
constants in the preprocessor rather than in the parser?
That is, for example, the pre-processor changes the three
characters 'a' to 0x61. and so on for other characters
including the wise ones.
For 'plain' characters it would depend on when in the PP the conversion
happens. For example
#define s(x) #x
must generate "'a'" so you can't change 'a' to 0x61 when reading tokens.
For the wide characters you are likely to have more trouble. L'a' is an
expression of type wchar_t and u'a' and U'a' are of type char16_t and
Thank You. I missed that point. I can avoid it successfully
by reading the source token by token so that when I see the
'a' I already know it will be stringized so I avoid converting
it to an integer.
I am sticking to the C89 POV so unsigned wide characters don't
enter into the picture. But it seems possible to label the wide
character number as type wchar_because I can make all constants
values (that is type plus address) in the preprocessor rather
than waiting for that in the parser. Complicates things somewhat
but not hopelessly.
The tiny practical gain is a small saving of effort in the parser
- but an increase in the preprocessor. Might not be worth the
PS: Of course, some integer constants might well be optimized out
of value form. I would just ignore the old value assignment leaving
a few holes in the final executable.