I
Ian Pilcher
I know that a pointer to a structure and a pointer to its first member
are largely interchangeable. Is that true for pointers to pointers?
I.e.:
struct foo {
int bar;
};
void int_fn(int **baz)
{
/* do stuff */
}
void foo_fn(struct foo *foo_ptr)
{
int_fn((int **)&foo_ptr); /* Is this cast defined? */
/* do other stuff with foo_ptr */
}
I have a sneaking feeling that it isn't, even though it's likely to work
on just about any mainstream implementation. I supposed that the "safe"
version would be something like:
void foo_fn(struct foo *foo_ptr)
{
int *int_ptr = (int *)foo_ptr;
int_fn(&int_ptr);
foo_ptr = (struct foo *)int_ptr;
/* do other stuff with foo_ptr */
}
Do I have that right?
Thanks!
are largely interchangeable. Is that true for pointers to pointers?
I.e.:
struct foo {
int bar;
};
void int_fn(int **baz)
{
/* do stuff */
}
void foo_fn(struct foo *foo_ptr)
{
int_fn((int **)&foo_ptr); /* Is this cast defined? */
/* do other stuff with foo_ptr */
}
I have a sneaking feeling that it isn't, even though it's likely to work
on just about any mainstream implementation. I supposed that the "safe"
version would be something like:
void foo_fn(struct foo *foo_ptr)
{
int *int_ptr = (int *)foo_ptr;
int_fn(&int_ptr);
foo_ptr = (struct foo *)int_ptr;
/* do other stuff with foo_ptr */
}
Do I have that right?
Thanks!