[C-prog-lang-l] why is the value of character constant an integer

Vladimír Kotal vlada at kotalovi.cz
Tue Feb 21 21:41:09 CET 2023


And by the way, I think this is an excellent question - keep thinking this way !


V. Kotal

On Tue, Feb 21, 2023, at 21:36, Vladimír Kotal wrote:
> 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
> _______________________________________________
> c-prog-lang-l mailing list
> c-prog-lang-l at mff.cuni.cz
> http://mbox.ms.mff.cuni.cz/listserv/listinfo/c-prog-lang-l
> 
-------------- next part --------------
HTML attachment scrubbed and removed


More information about the c-prog-lang-l mailing list