[TUHS] v7 K&R C
Brantley Coile
brantley at coraid.com
Tue Apr 28 04:02:29 AEST 2020
g, h and i are members of structures, the pointer of which is returned by the preceding function call. They have to be defined as pointers to functions returning a pointer to the following structure.
A simple example is:
typedef struct Node Node;
struct Node
{
Node *(*f)(void);
};
void
main(void)
{
Node *p;
p->f()->f()->f();
call();
(*((*((*p->f)()->f))())->f)();
}
// (*((*((*((*f)()->g))()->h))()->i))()
> On Apr 27, 2020, at 1:45 PM, Noel Chiappa <jnc at mercury.lcs.mit.edu> wrote:
>
>> From: Derek Fawcus
>
>> I think he means something like:
>> (*((*((*((*f)()->g))()->h))()->i))()
>
> So I've been confused by this thread, and I'm hoping someone can deconfuse me
> - but I think I may have figured it out.
>
> What's confusing me is that in C, the -> operator is followed by "an
> identifier [which] designates a member of a structure or union object" (I
> checked the spec to make sure my memory hadn't dropped any bits) - but g, h
> above are arguments; so I couldn't figure out what was going on.
>
> I think what may have happened is that initially the discussion was about C
> ("Pretty sure it was not in v7 C"), but then it switched to C++ - with which
> I'm not familiar, hence my confusion - without explicitly indicating that
> change (although the reference to Bjarne Stroustrup should been a clue). (And
> that's why I thought "f()->g()->h()->i()" was ad hoc notation for "calls f(),
> then calls g()".)
>
> Am I tracking now?
>
> Noel
>
>
More information about the TUHS
mailing list