Password sync plugin, and questions about plugin criticality

Will Fiveash William.Fiveash at sun.com
Tue Jun 27 15:36:36 EDT 2006


On Tue, Jun 27, 2006 at 02:11:31PM -0400, Ken Hornstein wrote:
> >> void pwupdate_init(void **context, krb5_context);
> >
> >As an aside, my experience with the C compiler's inability to strictly
> >type check "void *" function parameters has led me to think that it is
> >good to avoid "void *" parameters when possible.  
> >
> >Instead of "void *", something along the lines of:
> >
> >typedef struct context *context_t;
> >
> >void pwupdate_init(context_t *context, krb5_context);
> >
> >(The actual definition of struct context can be in a header private to
> >the plugin.)  Then the compiler can catch pointer problems that it can
> >not when "void *" is used.
> 
> I have no objection to doing this ... but for my own education, could you
> explain further?  Are you concerned about some random crap being passed
> in as a void *?  Or is there something else that I'm missing?

This code compiles without complaint:

foo(void *bar)
{
    printf("I hope bar is a string: %s\n", bar);
}

main()
{
    char *pointer=NULL;

    foo(pointer);
    foo(&pointer); /* this should cause a compiler warning */
    exit(0);
}

If an incomplete struct type pointer is used in the function parameter
spec for foo() then the compiler would catch the pointer type problem in
the second call to foo() statically.  Or stated another way, the C
compiler can not distinguish between void * and void ** and void ***,
and so on because a void has no type.

-- 
Will Fiveash
Sun Microsystems Inc.
Austin, TX, USA (TZ=CST6CDT)



More information about the krbdev mailing list