Im curious as to the more experienced members thoughts on this kind of arguement passing that is not much touched on, though i've seen it before in rare cases, usually to get around function callback parameter limitations. Are there any guarantees that this will work consistantly and portably?
Code:
#include <stdio.h>
typedef struct
{
float x;
float y;
}struct_t;
void func(void* arg)
{
int* v = arg;
struct_t x = *(struct_t*)(v+3);
int a = *(v+2), b = *(v+1), c = *v;
printf("func:\nx = (%.2f,%.2f), a = %d, b = %d, c = %d",
x.x,x.y,a,b,c);
}
int main(void)
{
struct_t x = {1,2.56};
int a = 1, b = 2, c = 3;
printf("main:\nx = (%.2f,%.2f), a = %d, b = %d, c = %d\n",
x.x,x.y,a,b,c);
func((&x,&a,&b,&c));
return 0;
}