my problem is that having this code:
int size=4384;
char buffer[size];
codifyDHCPmessage(buffer, message, size);
where message is an struct which only contains char[], and the function return in buffer, all the fields from the struct.
I test it going through the buffer array, and checking that all the fields are ok.
But my problem is that if i pass again that buffer into a new function as:
decodifyDHCPmessage(buffer,messageAux, size);
the first thing I do in that function is to check the size of buffer, which only tells me that is 4, when it’s suppossed to be 4384…. and I don’t know why.
I have to tell that I’m not an expert in C, and the pointer, and memory allocation issues are hard for me.
Thanks a lot in advance.
I suspect that your function signature looks like this:
(or similar)
The problem is that
[]in a function signature really means*, that is,char[]is reallychar*. In other words, the array argument decays to a pointer whose size is, unsurprisingly, 4.As far as I know (but I could be wrong …), C doesn’t allow you to pass arrays into functions at all, it just supports pointers. That’s why you need to pass the size as an explicit separate argument.