erik quanstrom
2013-02-17 02:38:09 UTC
i don't think this should link, since wrongaddr calls
fn with an Outer* not an Inner*.
#include <u.h>
#include <libc.h>
typedef struct Inner Inner;
typedef struct Outer Outer;
struct Inner {
int x;
};
struct Outer {
char buf[0x1000];
Inner;
};
void
wrongaddr(Outer *o)
{
static void fn(Outer*);
fn(o);
}
void
main(void)
{
Outer *o;
o = malloc(sizeof *o);
memset(o, 0, sizeof *o);
print("addr o %#p\n", o);
print("addr o.x %#p\n", &o->x);
wrongaddr(o);
}
static void
fn(Inner *i)
{
print("fn addr i.x %#p\n", &i->x);
}
; 6.cbug
addr o 0x4018f0
addr o.x 0x4028f0
fn addr i.x 0x4018f0
fn with an Outer* not an Inner*.
#include <u.h>
#include <libc.h>
typedef struct Inner Inner;
typedef struct Outer Outer;
struct Inner {
int x;
};
struct Outer {
char buf[0x1000];
Inner;
};
void
wrongaddr(Outer *o)
{
static void fn(Outer*);
fn(o);
}
void
main(void)
{
Outer *o;
o = malloc(sizeof *o);
memset(o, 0, sizeof *o);
print("addr o %#p\n", o);
print("addr o.x %#p\n", &o->x);
wrongaddr(o);
}
static void
fn(Inner *i)
{
print("fn addr i.x %#p\n", &i->x);
}
; 6.cbug
addr o 0x4018f0
addr o.x 0x4028f0
fn addr i.x 0x4018f0