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: Anonymous 2012-05-13 10:39

>>36
No, you misunderstood. The a[5] and b[5] above were declarations of arrays. It would be like writing this in C:

That's not correct you idiot. Sometime like a[5] is an array element. Something like

int a[5]

declares a to be array of 5 integers.
Yes, and you're passing by value the pointer to the array. In other words you're passing the array by reference. Way to be uselessly pedantic.

I'm not being pedantic. A pointer in C and a reference in a language C++ are two distinct beasts. The fact that you mix them up leads me to believe that you've never written any kind of actual code.

Name: Anonymous 2012-05-13 13:38

>>40
No they aren't. If C had "pass-by-reference", then you could stuff stuff like insert a node at the head of a linked linked without using any kind of indirection.

Name: Anonymous 2012-05-13 13:39

>>40
And this..

Pass-by-value and pass-by-reference are broader concepts than int foo(int x); and int bar(int &y);.

Makes no sense. Your grammar is as bad as your programming.

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