[comp.os.cpm] Aztec C II compiler bug

chad@qip.UUCP (Chad R. Larson) (09/12/90)

Manx Aztec C II, CP/M version 1.06d has a bug.

    i = sizeof "String";

Sets i to 2, not 7.

That is, sizeof when applied to a string literal returns the size
of a pointer to a character array, not the size of the array.
This is in conflict with both the BSD 4.3 compiler and the SysVr3
compiler, as well as K&R.

A workaround is to use the strlen function, although this costs
CPU at runtime rather than compile time.

Manx says they don't intend to fix it, as the demand for the native
C compiler doesn't justify it.  The MS-DOS based cross compiler gets
it right.

References:
    Kernighan & Ritchie  (Appendix A)
	2.5  "A string has type 'array of characters'...".
	7.2  "The sizeof operator yields the size, in bytes, of its
	operand.  When applied to an array, the result is the total
	number of bytes in the array."
    Harbison & Steele  (second edition)
	2.7.4  "The type of a string constant is "array of char",
	and its value is the n+1 characters".
        7.5.2 "...The sizeof operator does not of itself cause any of
        the usual conversions to be applied to the expression in
        determining its type...  For example, applying sizeof to the
        name of an array produces the total size of the array; this is
        possible because the sizeof operator does not cause the array to
        be converted to a pointer first."
-- 
Chad R. Larson          ...{mcdphx,asuvax}!anasaz!chad or chad@anasaz.UUCP
Anasazi, Inc. - 7500 North Dreamy Draw Drive, Suite 120, Phoenix, Az 85020
(602) 870-3330            "I read the news today, oh boy!"  -- John Lennon