[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: gEDA: Ancient bug found
martin@myri.com said:
> One one hand you are assuming that sizeof(char)=1 (is that guaranteed
> to be the case?), on the other hand you don't... :)
Actually, the size of a character is, by definition, 1.
<quote>
ISO/IEC 9899-1990
6.3.3.4 The sizeof operator
[...]
When applied to an operand that has type char, unsigned char, or signed char,
(or a qualified version thereof) the result is 1.
</quote>
So ``return_value = malloc(strlen(string)+1);'' is perfectly well defined
and portable. The other is excessive and pointless.
For the terminally pedantic:
<quote>
3.4 byte:
The unit of data storage large enough to hold any member of the basic
character set of the execution environment. It shall be possible to express
the address of each individual byte of an object uniquely.
</quote>
This is how DSP compilers can justify putting char into 32bit objects: that
is the smallest addressable unit that can hold a character. But even on those
processers, sizeof(char) == 1.
And all this applies to C++ as well.
--
Steve Williams "The woods are lovely, dark and deep.
steve@icarus.com But I have promises to keep,
steve@picturel.com and lines to code before I sleep,
http://www.picturel.com And lines to code before I sleep."