Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
2 registered members (OptimusPrime, AndrewAMD), 14,580 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
sizeof() in expressions #244692
01/06/09 10:44
01/06/09 10:44
Joined: Dec 2008
Posts: 271
Saturnus Offline OP
Member
Saturnus  Offline OP
Member

Joined: Dec 2008
Posts: 271
Hello,

according to the manual, sizeof() can not be used in expressions (stated on the page about structs).

However, a user has pointed out that sizeof() works in expressions, when a typecast to int is used:
malloc((int)sizeof(datatype) * n)

I would like to know, how save this method is.
At a first glance this workaround does the job fine (and its just written less verbosely).

Re: sizeof() in expressions [Re: Saturnus] #244693
01/06/09 10:55
01/06/09 10:55
Joined: Jul 2000
Posts: 28,024
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 28,024
Frankfurt
The method is safe as far as I can see. The (int) converts the definition to a temporary variable, which can then be used in expressions.

We intend to make the sizeof() anyway a real function in one of the next updates, because otherwise it's a potential source of bugs.

Re: sizeof() in expressions [Re: jcl] #244701
01/06/09 11:14
01/06/09 11:14
Joined: Dec 2008
Posts: 271
Saturnus Offline OP
Member
Saturnus  Offline OP
Member

Joined: Dec 2008
Posts: 271
All right, thank you!


Moderated by  old_bill, Tobias 

Gamestudio download | 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