|
|
|
|
|
by ericbb
3161 days ago
|
|
Haven't you misinterpreted "pass by reference" as "pass on the stack"? (In the following program, I'd say that x is passed on the stack but not passed by reference.) #include <stdio.h>
#include <stdlib.h>
struct example { void *a, *b, *c; };
void foo(struct example x)
{
x.a = &x;
if (x.a != NULL) puts("In foo(), x.a is not NULL.");
}
int
main(void)
{
struct example x = { .a = NULL };
printf("sizeof(x): %lu bytes (%lu bits).\n", sizeof(x), 8 * sizeof(x));
foo(x);
if (x.a == NULL) puts("In main(), x.a is NULL.");
return 0;
}
|
|
As you can see, structs used to be on the passed stack on x86-32. Most other/newer architectures use ABIs that pass the initial struct elements in registers.