There is a way to simulate a pass by reference in C, and that is to pass a pointer to a pointer. A demonstration:
Code:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
struct cat {
char name[32];
char bday[12];
};
void foo(struct cat ** me) {
printf("%s is located at %p in foo\n", (*me)->name, *me);
}
int main(void) {
struct cat *gargamel = malloc(sizeof(struct cat));
strncpy(gargamel->name, "Gargamel", 32);
strncpy(gargamel->bday, "4/7/2000", 12);
printf("%s is located at %p in main\n", gargamel->name, gargamel);
foo(&gargamel);
return 0;
}
Owner@PAVILION ~
$ ./a
Gargamel is located at 003D3DA8 in main
Gargamel is located at 003D3DA8 in foo
Owner@PAVILION ~
$
As you can see, no temporary is made. I like cats.