Q. is sizeof(char) always 1

Christopher Curtis ccurtis@ee.fit.edu
Fri Sep 25 16:58:00 GMT 1998


On Fri, 25 Sep 1998 grahams@rcp.co.uk wrote:

> The reason I'm asking this question is a lot of code
> in egcs assumes that sizeof(char) is 1 when allocating

According to the C specification, sizeof( char ) == 1 always.

I'm not 100% sure the Unicode implications of this.

> For example there are calls such as
>  p = (int *)xmalloc(N * sizeof(int *))

This is most definately incorrect.  Either p needs to be an int ** or the
sizeof be applied to an int, though I'm no expert.  ;-)

Christopher




More information about the Gcc-bugs mailing list