c - How to initialize pointers properly -


i have following code calls function uint32_pack. program compiles no errors in dev-c++ not produce correct result when 'tag' number. in visual studio program compiles produces errors , i'm guessing these errors why don't correct output when 'tag' even. i'm still trying head around pointers , i'm not sure went wrong when declaring them. help.

here code errors come from:

 1  int uint32_pack (uint8_t *fieldnumber, uint32_t value, uint8_t *out);  2  int main(){  3  uint32_t initvalue = 2;  4  int return_rv;    5  uint8_t *tag = (uint8_t *) malloc(sizeof(uint8_t));  6  *tag = 38;  7  uint8_t *tempout= (uint8_t *) malloc(30);  8  return_rv = uint32_pack (tag, initvalue, tempout);  9  free(tempout); 10  free(tag); 11  } 

and errors vs follows:

error c2143: syntax error : missing ';' before 'type' (on line 7) error c2065: 'tempout' : undeclared identifier        (on line 8) warning c4047: 'function' : 'unsigned char *' differs in levels of indirection 'int' (on line 8) warning c4024: 'uint32_pack' : different types formal , actual parameter 3 (on line 8)  error c2065: 'tempout' : undeclared identifier  (on line 9) warning c4022: 'free' : pointer mismatch actual parameter 1 (on line 9) 

the last 3 errors consequences of second, , second consequence of first. leaves first , third unexplained.

the first error occurs because using c89 , not c++ or c99; cannot declare variables after code in c89.

reverse order of lines 6 , 7 , should ok. (i think third error consequence of first, too, not definitive.)


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -