> From: Christopher Schultz [mailto:chris@christopherschultz.net]
> Subject: Re: [OT] JNI problem
>
> C99 probably allows this:
> char s[20];
> sizeof s;
>
> To yield 20, while strict, old-skool C would yield whatever "sizeof
> char*" would.
Not true; all versions of the C standard allowed the above, and all would evaluate to 20 for
sizeof. Contrary to popular belief, arrays and pointers are not equivalent, although they
can be interchanged in many circumstances - sizeof not being one of them.
> In any case, it's always best to use strlen() to figure out how many
> chars are in a string.
It's not just best, it's mandatory.
> I guess you mean dynamic sizing and not dynamic allocation.
I said it was not dynamic allocation; dynamic sizing is not quite appropriate either, since
the value is fixed for any given invocation of the function.
> It appears that:
> sizeof arr
> compiles to the equivalent of:
> val + sizeof char[6]
Yes, that's what I was pointing out.
> That's a pretty clever compiler.
It's required by the standard; not sure which version it went into, since I've only kept the
1999 one.
> Whatever happened to the days when compilers found ways to make
> your life miserable instead of actually helping you out? ;)
I believe that Visual Studio has cornered the make-your-life-miserable part of the market.
- Chuck
THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus
for use only by the intended recipient. If you received this in error, please contact the
sender and delete the e-mail and its attachments from all computers.
|