DragonFly BSD
DragonFly kernel List (threaded) for 2003-12
[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]

Re: libcaps question

From: Dave Leimbach <leimySPAM2k@xxxxxxx>
Date: 13 Dec 2003 18:32:55 -0600

Matthew Dillon <dillon@xxxxxxxxxxxxxxxxxxxx> writes:

> :I realize this is a work in progress but I find this to be a little 
> :difficult to keep track of.  Its probably just me :)
> :
> :    caps_port_t port;
> :    port = malloc(sizeof(*port));
> :    bzero(port, sizeof(*port));
> :    lwkt_initport(&port->lport, curthread);
> :    port->lport.mp_putport = cs_putport;
> :    port->lport.mp_waitport = cs_waitport;
> :    port->lport.mp_replyport = cs_replyport;
> :    port->lport.mp_refs = 1;
> :
> :Basically I would be more comfortable if port were (caps_port_t *).
> :
> :It would make the sizeof easier to get correct later so I don't just
> :accidentally allocate something that is the size of a pointer :).
> :
> :Dave
>     Most of the kernel structural _t typedefs are pointers, so that is
>     the convention I am using.  Use 'struct name' if you need the actual
>     structural type instead of a pointer.
>     So, e.g. thread_t, lwkt_msg_t, lwkt_port_t.

Ok so there is an idiomatic reason.  I generally leave the types as 
whatever_t and then always explicitly declare things to be pointers 
because that works for me.

>     There is a secondary reason for doing this and that is that we can,
>     if necessary, 'typedef struct fubar *fubar_t;' and use fubar_t in 
>     prototypes without having to bring in all the #include files necsesary
>     for struct fubar.  This reduces #include file pollution.

Yeah... But you can always do that regardless of whether the _t version
is a pointer or not I suppose.  Also you can't ever dereference
said pointer in your code if you omit the header that includes the struct
so I am not sure it really buys you *that* much.  You'd get an attempt
to derefence a pointer to an incomplete type.

Really its just a matter of what you feel like typing in the function
prototypes I guess.

void foo (some_t);
void foo (some_t *);

I guess I just feel that not typedefing things as pointers to types makes
me feel more balanced an symetrical in the code.

It really is nothing more than a matter of preference of idiom.

I will just learn to do it your way :).  Thanks for the explanation.


[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]