hardcoded constants

T. William Wells bill at twwells.uucp
Thu Dec 29 16:54:36 AEST 1988


In article <1988Dec26.021757.15813 at ziebmef.uucp> cks at ziebmef.UUCP (Chris Siebenmann) writes:
:  For true safety, I'd write this as
:
:       foo = malloc(Catspace(s,t)*sizeof(char) + sizeof('/'));
:
: (or redefine Catspace() to do this itself, depending on whether it
: returns a character or byte count), just in case someone produces a
: compiler where characters aren't single bytes.

Characters are required to be single bytes.  Note that this doesn't
prevent the implementer from using 16 bit bytes....

: [Corrections gratefully accepted; I don't think ANSI mandated
: sizeof(char) being one, although a lot of code will probably break if
: it isn't.]

Be grateful.

>From the May 13 draft, section 3.3.3.4:

"When applied to an operand that has type char, unsigned char, or
signed char, (or a qualified version thereof) the result is 1."

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



More information about the Comp.lang.c mailing list