Re: bootconfig
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.
It's because "hello" is considered an array of char by the compiler (char[6]),
not a pointer, so sizeof returns the size of the array.
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:
- Follow-Ups:
- Re: bootconfig
- From: karlheg@bittersweet.inetarena.com (Karl M. Hegbloom)
- References:
- Re: bootconfig
- From: karlheg@bittersweet.inetarena.com (Karl M. Hegbloom)