Gamestudio Links
Zorro Links
Newest Posts
Zorro version 3.0 prerelease!
by Grant. 02/24/26 22:21
WFO Training with parallel cores Zorro64
by Martin_HH. 02/24/26 19:51
ZorroGPT
by TipmyPip. 02/23/26 21:52
Camera always moves upwards?
by clonman. 02/21/26 09:29
Sam Foster Sound | Experienced Game Composer for Hire
by titanicpiano14. 02/19/26 13:22
AUM Magazine
Latest Screens
Dorifto samurai
Shadow 2
Rocker`s Revenge
Stug 3 Stormartillery
Who's Online Now
3 registered members (TipmyPip, clint000, Grant), 6,810 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
alx, ApprenticeInMuc, PatrickH90, USER0328, Sfrdragon
19199 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,075
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 28,075
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