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 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.

Name: Anonymous 2012-05-13 13:44

>>42
Barney McGrew

Name: Anonymous 2012-05-13 13:49

>>43
>>40 is just some moron hourly worker who has only written to code.

Name: Anonymous 2012-05-13 13:50

>>44
*written toy code*

Name: Anonymous 2012-05-13 14:47

Removing the word 'pointer' complete from the concept and replacing it with 'address' would solve 90% of the problems people have with C.

Name: Anonymous 2012-05-13 18:55

>>46
{i]address of an address of an address of an address of an int[/i]

Name: Anonymous 2012-05-13 19:14

>>47
Sounds like a bad Newgrounds point-and-click game.

Name: Anonymous 2012-05-13 19:16

>>1

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); }
//This is *NOT* consistent
//Who failed, so I knows whose ass to kick.


maybe you should consider suicide

Name: Anonymous 2012-05-13 21:34

the only person at fault is yourself for writing shoddy and inconsistent code

decide a programming style and stick to it

Name: Anonymous 2012-05-13 21:35

>50
how about i stick my dick inside your ass, see how that feels

Name: Anonymous 2012-05-14 0:44

>>38
You still don't fucking get it. The code fragment in >>33 is B, not C. The naked statement "a[5];" declares an array of five ints. "int" was not a keyword in B, because it was the only type; everything was an int.

Also, who the fuck mentioned C++? I'm not talking about C++ reference types. I'm talking about THE ACTUAL FUCKING MEANING OF THE WORD REFERENCE. If you pass the value of a pointer to an array, semantically you are passing the array by reference.

Yes the language passes the pointer by value, congratulations you fucking get that. Now think: WHY are we passing the value of a pointer? Oh, because we want to be able to REFER to the array contents in the function; we want a REFERENCE to the array, so we pass the POINTER BY VALUE.

Look up a dictionary some time you complete goddamn fucking moron.

Name: Anonymous 2012-05-14 2:17

>>38,41-42
The terms pass-by-value and pass-by-reference existed long before C++ or even C were created. They have long been used in programming language research to specify the semantics of a function call. Imagine a programming language that isn't C and where there are no pointers and you stumble upon a function call that looks like this:

f(x)

If x is passed by reference, it means that f operates on the same value. So if f modifies the structure of its argument in any way, the changes can be seen in x after the function returns.

On the other hand, if x is passed by value, then no matter what f does to its argument, you'll notice no change in the value of x.

If an argument is never modified within a function, there is no semantic difference between the two, and either can be used. Whether or not the compiler always makes a copy when a function is pass-by-value is an implementation detail.

However, there are pointers in C, so I understand that you are confused. Yes, everything is pass-by-value in C. Yet, when a parameter is a pointer, you sometimes say that the argument is passed-by-reference. But you might also pass a function a pointer to a struct and still say it's semantically call-by-value if the function doesn't modify the struct (and this is what const parameters are used for). So pointers can be used on a higher level to implement both pass-by-reference and pass-by-value. Your confusion stems from the fact that in C, the way parameters are passed is made explicit and you might have to take a step back to see the semantics. It might not be seen if you look too closely at the code (and more so if you think of programming as syntax).

>>44-45
And I'll have you know that my code has been burned to ROM and shipped on consumer devices all over the world. The devices are vibrators, one of which accidentally got your mother pregnant with you (oh wow, it's the 12th anniversery already).

Name: Anonymous 2012-05-14 2:36

Pass-by-name is superior, you're all mad and jelly after reading this post.

Name: Anonymous 2012-05-14 4:37

pass-by-my-dubz

Name: Anonymous 2012-05-14 19:40

>>50
It has nothing to do with style. This is actually one place where C is quite inconsistent, and for the oldest reason in the book: backwards compatibility.

Reminds me of this: http://www.astrodigital.org/space/stshorse.html

Name: Anonymous 2012-05-14 19:41

>>54
Could you show an interesting example of call-by-name that you didn't copy from wikipedia?

Name: Anonymous 2012-05-15 3:41

>>57
begin
   integer i;
   real procedure sum (i, lo, hi, term);
      value lo, hi;
      integer i, lo, hi;
      real term;
      comment term is passed by-name, and so is i;
   begin
      real temp;
      temp := 0;
      for i := lo step 1 until hi do
         temp := temp + term;
      sum := temp
   end;
   comment note the correspondence between the mathematical notation and the call to sum;
   print (sum (i, 1, 100, 1/i))
end

Name: Anonymous 2012-05-15 5:06

>>57
#define MIN(x, y) (x < y ? x : y)

MIN(1, 2)

Name: Anonymous 2012-05-15 6:08

hello how are you

Name: Anonymous 2012-05-15 8:15

>>60
Hello, I am fine, thank you.

Name: Anonymous 2012-05-15 8:38

>>59
Hey, never thought of that. Good point.

Name: Anonymous 2012-05-15 9:28

ITT: OP tries to know what hes talking about and fails

Name: Anonymous 2012-05-15 9:29

>>63
how do you like /prog/ so far?

Name: Anonymous 2012-05-15 21:34

>>52
U MAD?

Name: Anonymous 2012-05-15 21:40

Name: Anonymous 2012-05-15 21:49

>>64
Its not bad, seen some pretty good threads mixed in with some pretty bad ones

Name: b 2012-05-16 1:22

Name: someone@gnu.ait.mit.edu !!aU6oKXi2C81HZ4k 2012-05-16 12:31

>>53
Yet, when a parameter is a pointer, you sometimes say that the argument is passed-by-reference.

With all due respect, you are a god damn fucking moron.

Name: Anonymous 2012-05-16 15:34

int a[1] = { 1 };
int *b = malloc(sizeof(int));    *(b+0) = 1;

so isnt an array just another notation for pointer? I dont get the difference here

Name: Anonymous 2012-05-16 16:08

>>70
Kindly review >>26 for a start.

Name: Anonymous 2012-05-16 18:52

C is undefined shit.

Name: Anonymous 2012-05-16 21:25

>>26
$ ./ptrsize
sizeof(ar)  = 40
sizeof(pt)  = 8

Name: Anonymous 2012-05-16 21:49

>>73
THANKS FOR THE UPDATE BIG BEN

Name: Anonymous 2012-05-17 6:43

$ echo '#include <stdio.h>
int main()
{
    char a[8], *p = a;
    printf("sizeof a = %zd\nsizeof p = %zd\n", sizeof a, sizeof p);
    return 0;
}' | gcc -xc -o size-test -
$ ./size-test
sizeof a = 8
sizeof p = 8

Yeah, right. Try again ``faggots''

Name: Anonymous 2012-05-20 18:18

$ echo '#include <stdio.h>
int main()
{
    char a[8], *p = a;
    printf("sizeof a = %zd\nsizeof p = %zd\n", sizeof a, sizeof p);
    return 0;
}' | gcc -xc -o size-test -
$ ./size-test
sizeof a = 5
sizeof p = 1

Name: autism is the disease 2012-05-20 20:27

dubz are the cure

Name: Anonymous 2012-05-21 2:57

It should be %zu and not %zd.

Name: Anonymous 2012-05-21 4:23

C++ is shit, undefined
LISP is shit, parenthesized
Python is shit, FIOCified
Java is shit, objectified
COBOL is shit, enterprised
Malbolge is shit, obfuscified
BASIC is shit, labelized
PHP is shit, MYSQL CONNECTION ERRORfied

Name: Anonymous 2012-05-21 4:41

>>79
and the LISP one is the only recursive acronym of all of them

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