const and struct pointers
D'Arcy J.M. Cain
darcy at druid.uucp
Sun Feb 25 13:53:27 AEST 1990
In article <90054.232325CMH117 at psuvm.psu.edu> CMH117 at psuvm.psu.edu (Charles Hannum) writes:
>
>The double is passed by value; so dereferencing it works fine. But the
>struct is passed by reference (as are *all* structures in C!). In reality,
>you need to pass a "struct qwert *" to the function. Normally, the compiler
>takes the reference automatically, but you are trying to do this in reverse.
>Thus, it does not work; you simply can't pass a structure by value.
>
Bzzzzzzt!!
That may be true for K&R1 but both K&R2 and ANSI both allow passing
structures by value. Granted this may not be something that you want
to do too often but it is permissible. Even K&R1 hinted that it would
one day be allowed.
You can even do something like the following:
struct qwert foo;
struct qwert bar(struct qwert x);
...
foo = bar(foo);
Of course sending the address would be more efficient in the above example.
--
D'Arcy J.M. Cain (darcy at druid) | Thank goodness we don't get all
D'Arcy Cain Consulting | the government we pay for.
West Hill, Ontario, Canada |
(416) 281-6094 |
More information about the Comp.lang.c
mailing list