Re: struct and function-pointer casting



Eric Sosman <eric.sosman@xxxxxxx> wrote:
> No; the type of `derived_func' does not match the
> type of the `func' element in `struct Base', so the
> compiler should object to the initialization. One
> simple fix is
>
> void derived_func(struct Base *b) {
> struct Derived *d = (struct Derived*)b;
> ...
> }

Ok, not as neat as it would be in my code but I think I can
live with it.

> The conversions of the struct pointers are all right:
> any struct pointer can be converted to and from a pointer
> to the struct's first element (unless that element is a
> bit-field; you can't point to a bit-field).

That is good.

Thanks for your answer.
.



Relevant Pages

  • Re: Type information in structs of different types
    ... and you can use any of the struct types to access them. ... It's impossible for common initial sequences to be laid out differently ... And in that case, using a union would help, but at the cost of every ... But since we're told that struct pointers are ...
    (comp.lang.c)
  • Re: Improving memory consumption in the container library
    ... struct list_element *Next; ... Presumably you're using the struct hack, ... You appear to be assuming an implementation where struct pointers are ... ever actually want to allocate sizeofbytes. ...
    (comp.lang.c)
  • Re: Questions about memmove
    ... > copy struct pointers over using 'memmove'. ... EMPLOYEE *employee; ... memmove(copy, emp, sizeof(EMPLOYEE)); ...
    (comp.lang.c)
  • Re: 406 Not Acceptable (was Re: "--All You Zombies--" title)
    ... I meant exactly what I declared, two struct pointers and a struct pointer ... What compiler are you using. ... The gcc compiler says "struct * pea" ...
    (rec.arts.sf.written)
  • [GIT PULL] header cleanups/fixes for v2.6.30
    ... Standardize/fix type usage in exported headers and drop the ... make most exported headers use strict integer types ... headers_check fix: alpha, statfs.h ... struct kvm_regs { ...
    (Linux-Kernel)