Displaying pointers with diag statement

Posted By: Aku_Aku

Displaying pointers with diag statement - 11/19/17 15:25

Hello Community!

I would like to know your opinion this code, i want to display a pointer with diag.
Code:
typedef struct MY_DEF {
  int my_number;
} MY_DEF;
MY_DEF* my_type;
my_type = malloc(sizeof(MY_DEF));
diag(str_printf(str, "nPointer:%d",(long)my_type));


Do you see any problem with this code?
Posted By: Quad

Re: Displaying pointers with diag statement - 11/19/17 17:09

normally in C you would do:

Code:
str_printf(str, "nPointer:%p",(void*)my_type)



(notice %p and void* cast)
but i am not sure how lite-c actually handles pointers internally so results may vary.

Edit: you get different results either way depending on whether PRAGMA_POINTER is defined or not.
Posted By: Aku_Aku

Re: Displaying pointers with diag statement - 11/19/17 22:46

Thanks, it seems to me it is better than mine, furthermore p is a regular type in formatting strings.
I tried this format, and finally i will stay with my original type, because (str, "nPointer:%p",(void*)my_type) gives back a hexadecimal number, mine gives back a decimal number.
© 2024 lite-C Forums