[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: bootconfig



>>>>> "Eric" == Eric Delaunay <delaunay@lix.polytechnique.fr> writes:

    Eric> Karl M. Hegbloom wrote:
    >> >>>>> "Mark" == Mark van Walraven <markv@wave.co.nz> writes:
    >> 
    Mark> On Thu, Feb 17, 2000 at 01:39:06PM -0800, Karl M. Hegbloom wrote:
    >> >> Ok; I looked; using `sizeof' on a char * "string" isn't right, is it?
    >> >> I think you have to use strlen then, or you'll get the size of a char
    >> >> *, not the length of the string.  I've changed it to strlen in the
    >> >> branch already.
    >> 
    Mark> Where have I done this?  Note that a string literal is not the same size as
    Mark> char *.  Try compiling and running:
    >> 
    Mark> main() { exit(sizeof "hello"); }
    >> 
    Mark> ... the exit code should be 6.
    >> 
    >> Oh.  I just checked, and you're right.  I thought it would return the
    >> size of a char *, which is probably 4.

    Eric> It's because "hello" is considered an array of char by the compiler (char[6]),
    Eric> not a pointer, so sizeof returns the size of the array.

 Well, yes, that's obvious.  Do you know if that behaviour is part of
 the ANSI standard?


Reply to: