Re: bootconfig
Karl M. Hegbloom wrote:
> >>>>> "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?
I guess, but I don't have ANSI C book on my own, only one for C++.
Anyway my book is telling so. And also the K&R C compiler SUN delivered in
the past along with SunOS-4.
Regards.
--
Eric Delaunay | S'il n'y a pas de solution, c'est qu'il n'y
delaunay@lix.polytechnique.fr | a pas de problème. Devise Shadok.
Reply to:
- References:
- Re: bootconfig
- From: karlheg@bittersweet.inetarena.com (Karl M. Hegbloom)