#include <stdio.h>
struct s{
char c;
int a;
long l;
};
struct s *get_s_ptr(int *a_ptr)
{
struct s r;
return (struct s *)((unsigned long)a_ptr - ((unsigned long)&r.a - (unsigned long)&r));
}
main()
{
struct s r, *r_ptr;
r.c = 'A';
r.a = 10;
r.l = 123456789;
printf("r.c=%c r.a=%d r.l=%ld\n", r.c, r.a, r.l);
r_ptr = get_s_ptr(&r.a);
printf("r_ptr->c=%c r_ptr->a=%d r_ptr->l=%ld\n", r_ptr->c, r_ptr->a, r_ptr->l);
}
struct s{
char c;
int a;
long l;
};
struct s *get_s_ptr(int *a_ptr)
{
struct s r;
return (struct s *)((unsigned long)a_ptr - ((unsigned long)&r.a - (unsigned long)&r));
}
main()
{
struct s r, *r_ptr;
r.c = 'A';
r.a = 10;
r.l = 123456789;
printf("r.c=%c r.a=%d r.l=%ld\n", r.c, r.a, r.l);
r_ptr = get_s_ptr(&r.a);
printf("r_ptr->c=%c r_ptr->a=%d r_ptr->l=%ld\n", r_ptr->c, r_ptr->a, r_ptr->l);
}