int writeFile(char *name, unsigned char *buff, size_t *size,const char *dir )
FILE * pFile;
pFile = fopen ( name, "wb");
//(gdb) print *size
//$5 = 3832907636190596508
fwrite (buff , sizeof(unsigned char), *size, pFile);
int writeDmpFile(GTree *tree, char *filename)
int size =0;
g_tree_foreach(tree, (GTraverseFunc)writeDmpFileLine, ¶ms);
sprintf (dmpfilename, "InstrumentList_FULL.csv_%.*s", 15, filename);
//here (gdb) print size
//$1 = 380316
writeFile(dmpfilename, ( unsigned char *)params.buff, ( size_t *)&size , dmpdir);//(size_t *)params.size, dmpdir);
There are two fundamental problems here.
sizeto be an
int, but really it needs to be a
size_t. Change its type to
writeFile. You should be passing it as a const value param. You don't need to modify it, nor do you. So make that clear in the signature of the function.
As a general rule, any time you encounter a type mismatch compiler error and are tempted to suppress the error with a cast, you are almost certainly making a mistake. The compiler reported an error because you made a mistake. Sure you can shut the compiler up, but experience tells me that the compiler is usually right, and we humans are very good at making mistakes.
So, don't suppress type mismatch compiler errors with casts. Seek to understand why the types don't match and thus resolve the problem.