Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
M1 Oversampling
by jcl. 04/26/24 11:12
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
Eigenwerbung
by jcl. 04/26/24 11:08
MT5 bridge not working on MT5 v. 5 build 4160
by EternallyCurious. 04/25/24 20:49
Trading Journey
by howardR. 04/24/24 20:04
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
Scripts not found
by juergen_wue. 04/20/24 18:51
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
4 registered members (AndrewAMD, EternallyCurious, Petra, 1 invisible), 795 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Mega_Rod, EternallyCurious, howardR, 11honza11, ccorrea
19048 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: 993
Budapest
Aku_Aku Offline OP
User
Aku_Aku  Offline OP
User

Joined: Sep 2009
Posts: 993
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 Offline
Senior Expert
Quad  Offline
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: 993
Budapest
Aku_Aku Offline OP
User
Aku_Aku  Offline OP
User

Joined: Sep 2009
Posts: 993
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