[comp.lang.c] sizeof of struct field

quiroz@cs.rochester.edu (Cesar Quiroz) (10/27/89)

Under what conditions do you have

    (1) access to the name of a struct,
    (2) not an instance of the struct around ?

I cannot come up with an example where I would need sizeof of a
field, and not have an instance around.  That, of course, is not an
argument.  But, if it never happens, then there is no problem to be
fixed.

For the most part, I can imagine:

    #include <defshere.h>

    struct foo *
    make_foo(...)
    {
        struct foo result = (struct foo *) malloc(sizeof(struct foo));
        ...
        /* here I can use sizeof(result->slot) */
    }

    foobar
    use_foo(struct foo one,...)
    {
        /* here I can use sizeof(one.slot) */
    }

So, when would `sizeof( ((struct foo *)0)->slot )' be useful and not
one of the cases above be available?
-- 
                                      Cesar Augusto Quiroz Gonzalez
                                      Department of Computer Science
                                      University of Rochester
                                      Rochester,  NY 14627