🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #6221

Re: const and struct pointers

#6221
From: D'Arcy J.M. Cain
Date: Sun, 25 Feb 1990 02:53
31 lines
1590 bytes
In article <90054.232325CMH117@psuvm.psu.edu> CMH117@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@druid)     |   Thank goodness we don't get all 
D'Arcy Cain Consulting             |   the government we pay for.
West Hill, Ontario, Canada         |
(416) 281-6094                     |
Technical Details
Message-ID: <1990Feb25.025327.17710@druid.uucp>
Path: arc1-ca.pugleaf.net!utzoo!attcan!telly!druid!darcy
References: <1214@watserv1.waterloo.edu> <90054.232325CMH117@psuvm.psu.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!telly!druid!darcy
From: darcy@druid.uucp (D'Arcy J.M. Cain)
Newsgroups: comp.std.c,comp.lang.c
Subject: Re: const and struct pointers
Message-ID: <1990Feb25.025327.17710@druid.uucp>
Date: 25 Feb 90 02:53:27 GMT
References: <1214@watserv1.waterloo.edu> <90054.232325CMH117@psuvm.psu.edu>
Reply-To: darcy@druid.UUCP (D'Arcy J.M. Cain)
Organization: D'Arcy Cain Consulting, West Hill, Ontario
Lines: 31