[C-prog-lang-l] why is the value of character constant an integer
Vladimír Kotal
vlada at kotalovi.cz
Tue Feb 21 21:36:26 CET 2023
Hi all,
someone asked on Monday after the lecture why is the value of character constant an int (rather than char).
I think this is historical and for flexibility/compatibility. For instance, multi-character constants (e.g. 'ABC' - with single quotes) _usually_ (implementation defined - another type of behavior) result in values larger than a char (signed or unsigned) can hold.
By the way, you can verify compiler behavior on godbolt.org, it lets you select various compilers and versions. Here's one for the multi-char constant: https://godbolt.org/z/zjWej99xc
Most of the compilers available there implement the value the same, but not all of them (try the Chibicc compiler).
Best regards,
V. Kotal
-------------- next part --------------
HTML attachment scrubbed and removed
More information about the c-prog-lang-l
mailing list