Questions about pointers to objects and pointers to functions



Hello,

I've got a few questions:

1) Given the two structs
struct A {
    int x;
};

and

struct B {
    struct A y;
    int z;
};

is it ok to treat a "pointer to an object of type struct B" as a "pointer to an object of type struct A"?
(I think someone asked something like this some time ago, but unfortunately I can't find the article anymore)


2) When I now have a function pointer of type
void (*fpa)(struct A *, int);
and a function pointer of type
void (*fpb)(struct B *, int);

and the corresponding functions
void fa(struct A*,int);
and
void fb(struct B*,int);

is it ok to assign a "pointer to fa" to fpb and call the function through fpb with a "pointer to an object of type struct B" as the first parameter?

Thanks in advance
Marc Thrun
.



Relevant Pages

  • Re: Memory Structure Pointer Problems
    ... typedef struct sta { ... char* name; ... int num_cmpnds; ... A pointer to a struct cmp is almost ...
    (comp.lang.c)
  • gcc, aliasing rules and unions
    ... struct B {int x, y;}; ... A struct pointer can be converted to another ... Also I don't know what the "effective type" of a union member is. ...
    (comp.lang.c)
  • Re: creating a pointer to a imbeded struct causes C2065
    ... Generally, with async sockets you don't need threading, and the value of a thread pool ... typedef struct T_Smoo ... smart pointer, like boost::shared_ptr (with it, basically, you don't need to ...
    (microsoft.public.vc.mfc)
  • Re: invalid pointer adress
    ... >> pointer causes the program to exit with a core dump. ... struct s2{void *p;}; ... int leseExterneHinweise_masch_storno ... typedef struct s_AusdatFeldbeschreibung ...
    (comp.lang.c)
  • Re: creating a pointer to a imbeded struct causes C2065
    ... typedef struct T_Smoo ... struct Smoo ... smart pointer, like boost::shared_ptr (with it, basically, you don't need to ...
    (microsoft.public.vc.mfc)