I have something similar to this code in my application:
#include <stdlib.h>
#include <stdio.h>
typedef struct STH
{
double *buff;
int size;
}STH;
void fun1(STH *s)
{
fun3(s->buff, s->size);
}
void fun3(double *buff, int n)
{
int i = 0;
printf("N = %d\n", n);
for(i=0; i<n; i++)
printf("%d\n", buff[i]);
}
void fun2()
{
STH s;
s.size = 4;
s.buff = malloc(sizeof(double) * s.size);
fun1(&s);
}
int main()
{
fun2();
return 0;
}
When I try to print out the buffer in fun3, gdb says that there is an error in fun3. When I try to print out (in fun2) the value of the s->size, there is an error (instead of 4 it prints out strange numbers ....)