N
Nelu
Keith said:Nelu said:Nelu said:Keith Thompson wrote:<snip>Passing it as a parameter is irrelevant.
I'm not sure how irrelevant it is. Check this code:
void foo(char b[]) {
b++;
printf("%ld\t%ld\n",sizeof(b),sizeof(char*));
}
b is not an array; it's a pointer object. And it's not a const
object; it's merely initialized to the value of the actual argument.
In a parameter declaration, "char b[]" is merely an alias for "char *b".
This is independent of the rules for implicit conversion of array
names to pointer values.
Also, "%ld" is not the correct format for a size_t. You can use "%zu"
if your library conforms to C99, or you can convert the operand to
the expected type:
printf("%d\t%d\n", (int)sizeof b, (int)sizeof(char*));
int main(void) {
char arr[10];
foo(arr);
Here arr is converted to a pointer value, equivalent to &arr[0].
This value is passed to foo and copied to b.
[snip]printf("%ld\n",sizeof(arr));
return 0;
}
I didn't use %zu (although it works on my gcc) just in case someone
tries it on Turbo C . I forgot to cast, though, and -Wall didn't say
anything, probably because they are the same type.
The example was just to show that b (in foo) is a pointer object in
accordance with what CBFalconer was saying.