libcontrol

26 views
Skip to first unread message

Noel Hunt

unread,
Feb 17, 2025, 8:25:05 PMFeb 17
to plan9port-dev
I am trying to compile libcontrol under plan9port. Various
of the structures used in the code rely on the Plan9 compiler's
support for anonymous structure elements of an aggregate. This
can be straightforwardly dealt with by naming the structure, e.g., we have such declarations as

struct Group {
        Control;
        ,,,,
};

and

struct Box {
        Control;
        ....
};

where 'Control' is a previously defined aggregate, so to make
this legal for non-Plan9 compilers

struct Group {
        Control c;
        ...
};

Group *g;

....g->event      =>      g->c.event

would seem to be the correct procedure, except there are some
cases like this

void
_ctladdgroup(Control *c, Control *q){
        Group *g = (Group*)c;
        ...

where'_ctladdgroup' is called with a real Control* struct as
argument one, not a cast, and then tries to cast this to a
Group*, and then references elements of the Group struct:

        g->kids = realloc(...);

This just will not work, so can someone explain what is going on
with this code, and how it compiles, and runs, under Plan9?



Dan Cross

unread,
Feb 17, 2025, 8:44:10 PMFeb 17
to noel...@gmail.com, plan9port-dev
I haven't looked at this in detail, but at a glance.... The first
element in a Group is a Control. My guess is that this code "knows"
that the control it receives is embedded inside of a Group and
therefore that it can cast to the containing type.

- Dan C.

Noel Hunt

unread,
Feb 17, 2025, 9:06:36 PMFeb 17
to plan9port-dev
Yes, I see what you mean. I'll have to look more closely at
what is being passed around in that case.

Thanks.

Jacob Vosmaer

unread,
Feb 18, 2025, 2:59:11 AMFeb 18
to plan9port-dev
Isn't this something you can do with C structs in general? Cast a pointer the struct to a point to its first member. This casting thing sounds orthogonal to the Plan 9 C anonymous struct member feature.

Op di 18 feb 2025 om 03:06 schreef Noel Hunt <noel...@gmail.com>:
--

---
You received this message because you are subscribed to the Google Groups "plan9port-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to plan9port-de...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/plan9port-dev/6d79a2d3-6ac6-41ec-8014-e41b7b577bc5n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages