Gamestudio Links
Zorro Links
Newest Posts
FXCM demo test failed
by jcl. 01/13/26 09:39
Camera always moves upwards?
by NeoDumont. 01/12/26 09:39
Alpaca Plugin v1.5.2 Release
by kzhao. 01/11/26 13:42
Alpaca Plugin v1.4.0
by kzhao. 01/11/26 13:38
separating groups of 3 digits by a comma
by joe_kane. 01/11/26 00:01
MRC.c and WFO
by joe_kane. 01/10/26 23:58
BarOffset (default = 940 for daily bars?
by joe_kane. 01/10/26 23:46
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
1 registered members (1 invisible), 3,532 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
promfast, joe_kane, Namitha_NN, Syndrela, agasior
19190 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,051
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

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