[CrackMonkey] Another nail in the Pine coffin

Michael Jennings mej at valinux.com
Sat Sep 30 21:22:32 PDT 2000


On Sunday, 01 October 2000, at 04:29:25 (+0100),
Paul J Collins wrote:

>     Bad> char can be a 64-bit type, d00d. Of course it depends on your
>     Bad> implementation!
> 
> char is defined as the smallest addressable quantity on the machine
> in question.  This is rarely not a byte.

Somebody needs to re-read their C FAQ.

ftp://rtfm.mit.edu/pub/usenet-by-group/comp.lang.c/C-FAQ-list

7.8:    I see code like

                char *p = malloc(strlen(s) + 1);
                strcpy(p, s);

        Shouldn't that be malloc((strlen(s) + 1) * sizeof(char))?

A:      It's never necessary to multiply by sizeof(char), since
        sizeof(char) is, by definition, exactly 1.  (On the other
        hand, multiplying by sizeof(char) doesn't hurt, and in some
        circumstances may help by introducing a size_t into the
        expression.)  See also question 8.9.

        References: ISO Sec. 6.3.3.4; H&S Sec. 7.5.2 p. 195.

char is ALWAYS 1 byte, 8 bits.  The only thing about that which
changes between platforms is whether those 8 bits are interpreted as
signed (7 bits of data plus a sign bit) or unsigned (8 data bits) by
default.

Michael

-- 
Michael Jennings (a.k.a. KainX)  http://www.kainx.org/  <mej at eterm.org>
Software Engineer, VA Linux Systems       Author, Eterm (www.eterm.org)
-----------------------------------------------------------------------
 "I believe God's grace is so incredible that He saves those who so
  much as grunt in His general direction, as long as it is from their
  heart."    -- Rick Durrance, Youth Pastor, Wilmore UMC (paraphrased)





More information about the Crackmonkey mailing list