Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Why is C not consistent

Name: Anonymous 2012-05-10 1:43

Take the following two declarations "int arr[3]" and "int *ptr".

Both require different storage, but in usage both are identical. This behaviour  is known, and it is not the consistency I am talking about.

Take the following two declarations:

void funcarr(int a, int arr[3], int c)
{ printf("%d\n", &c-&a); }

void funcptr(int a, int *ptr, int c)
{ printf("%d\n", &c-&a); }

For funcarr, all three arguments are intended to be call by value. So I would expect the stack to contain
a,arr[0],arr[1],arr[2],c
but it does not. The stack contains
a,&arr[0],c

This is *NOT* consistent, and gives a false impression that the elements of arr[] will not change within the lifetime of the function.

Who failed, so I knows whose ass to kick.

Name: Cudder !MhMRSATORI!FBeUS42x4uM+kgp 2012-05-12 7:08

>>25
you can declare structs without fields so no base types
No, that would be equivalent to a base type of void, like a function with no parameters.

pointers do not require a base type since the base type does not affect it's behavior
an address is an address
These are in direct contradiction to each other. If you think only in terms of elements then the former is true but the latter is not, in the context of pointer arithmetic. Similarly if you think in terms of byte (or however wide the memory happens to be) addresses, then the former is false but the latter is true.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List