Gamestudio Links
Zorro Links
Newest Posts
loading historical data 1st time
by AndrewAMD. 04/14/23 12:54
Trade at bar open
by juanex. 04/13/23 19:43
Bug in Highpass2 filter
by rki. 04/13/23 09:54
Adding Limit Orders For IB
by scatters. 04/11/23 16:16
FisherN
by rki. 04/11/23 08:38
AUM Magazine
Latest Screens
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Hecknex World
Who's Online Now
3 registered members (AndrewAMD, juanex, Grant), 1,018 guests, and 8 spiders.
Key: Admin, Global Mod, Mod
Newest Members
rki, FranzIII, indonesiae, The_Judge, storrealba
18919 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: 27,935
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,935
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 | 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