hardcoded constants

Dave Jones djones at megatest.UUCP
Fri Dec 23 09:46:12 AEST 1988


>From article <1797 at dataio.Data-IO.COM>, by bright at Data-IO.COM (Walter Bright):
> In article <1104 at goofy.megatest.UUCP> djones at megatest.UUCP (Dave Jones) writes:
> <foo =  malloc( strlen(s) + strlen(t) + sizeof('\0'));
> <Tells it all.  And keeps the reader on track, not grepping around
> <for macros.
> 
> But doesn't sizeof('\0') return sizeof(int), instead of sizeof(char)?
> Remember, the integral promotions are being done.


Gack! You are correct. Due to certain intermittent reduced neurological
function (sometimes I can be real dumb), it is hard for me to remember
that in C, "character" constants are of type int, not char. Seems goofy
to me. Can anyone suggest a rationale, so that I can remember this arcane
fact?

Okay. You get bucked off, you climb right back in the saddle, right?


How about,


  foo =  malloc( strlen(s) + strlen(t) + sizeof((char)'\0'));



More information about the Comp.lang.c mailing list