hardcoded constants

T. William Wells bill at twwells.uucp
Fri Dec 23 20:53:00 AEST 1988


In article <410 at aplcen.apl.jhu.edu> arrom at aplcen.UUCP (Ken Arromdee (600.429)) writes:
: >How about sizeof('\0') is equal to the size of an integer, which is
: >unlikely to be 1?
: >Remember, in C, character constants are integer constants.
:
: I was under the impression that "sizeof" is done at compile time and isn't
: really a function, so this would correctly return 1.

Well, you are right that sizeof is done at compile time, and it isn't
a function. But it won't return 1.

Sizeof is an operator. The thing it is operating on is a character
constant. In C, a character constant *is* an integer. Thus sizeof a
character constant must the the same as the sizeof an integer. (Now,
for the gurus: am I right in saying integer, or should I say `of some
integral type'?)

---
Bill
{uunet|novavax}!proxftl!twwells!bill



More information about the Comp.lang.c mailing list