Gamestudio Links
Zorro Links
Newest Posts
Blobsculptor tools and objects download here
by NeoDumont. 03/28/24 03:01
Issue with Multi-Core WFO Training
by aliswee. 03/24/24 20:20
Why Zorro supports up to 72 cores?
by Edgar_Herrera. 03/23/24 21:41
Zorro Trader GPT
by TipmyPip. 03/06/24 09:27
VSCode instead of SED
by 3run. 03/01/24 19:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (Quad, aliswee), 835 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sakolin, rajesh7827, juergen_wue, NITRO_FOREVER, jack0roses
19043 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Displaying pointers with diag statement #469522
11/19/17 15:25
11/19/17 15:25
Joined: Sep 2009
Posts: 991
Budapest
Aku_Aku Offline OP
User
Aku_Aku  Offline OP
User

Joined: Sep 2009
Posts: 991
Budapest
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?

Re: Displaying pointers with diag statement [Re: Aku_Aku] #469524
11/19/17 17:09
11/19/17 17:09
Joined: Oct 2007
Posts: 5,210
İstanbul, Turkey
Quad Online
Senior Expert
Quad  Online
Senior Expert

Joined: Oct 2007
Posts: 5,210
İstanbul, Turkey
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.

Last edited by Quad; 11/19/17 17:13.

3333333333
Re: Displaying pointers with diag statement [Re: Quad] #469528
11/19/17 22:46
11/19/17 22:46
Joined: Sep 2009
Posts: 991
Budapest
Aku_Aku Offline OP
User
Aku_Aku  Offline OP
User

Joined: Sep 2009
Posts: 991
Budapest
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.

Last edited by Aku_Aku; 11/19/17 22:53. Reason: final solutions

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1