Gamestudio Links
Zorro Links
Newest Posts
ZorroGPT
by TipmyPip. 03/28/26 14:01
TMFs on options in live trading
by Spirit. 03/26/26 19:52
TDAmeritrade plugin with new Schwab accountt?
by AndrewAMD. 03/24/26 17:11
Black Book, 4th edition
by jcl. 03/17/26 09:28
AUM Magazine
Latest Screens
Dorifto samurai
Shadow 2
Rocker`s Revenge
Stug 3 Stormartillery
Who's Online Now
2 registered members (TipmyPip, Grant), 4,021 guests, and 7 spiders.
Key: Admin, Global Mod, Mod
Newest Members
mredit, vestriaa, Lukudo, mldenoiser, the1
19204 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
sizeof(TICK) getting 0? #461738
08/18/16 19:50
08/18/16 19:50
Joined: Jun 2016
Posts: 29
panz Offline OP
Newbie
panz  Offline OP
Newbie

Joined: Jun 2016
Posts: 29
Some of the data import/export scripts depend on sizeof(TICK) to calculate the number of records in the binary content read from a file. However, when I made some changes to ExportBar.c so it can loop through multiple files, I found the script crashing. Some debugging showed that sizeof(TICK) is 0 in my script!

After a few failed attempts, I realized that there must be some combinations of codes in ExportBar.c that can trigger the compiler to give a correct value (24) to sizeof(TICK) (though "typedef struct TICK" is defined in trading.h and included while including default.c by default). I just couldn't find out what that condition is. Does anyone know about this?

An extremely simple example script that will show sizeof(TICK) as 0:

function main()
{
printf("\nsizeof(TICK)=%d\n", sizeof(TICK));
}

Thanks!

Re: sizeof(TICK) getting 0? [Re: panz] #461749
08/19/16 10:40
08/19/16 10:40
Joined: Jul 2000
Posts: 28,090
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 28,090
Frankfurt
Interesting. This is indeed a bug in the sizeof macro. No one noticed it all the time because it only happens with structs that are never used in the script.

This bug will be fixed in the next update. Until then, use this workaround when your script accesses no TICK element, but still needs the TICK size:

function main()
{
TICK* t; t->time = 0;
printf("\nsizeof(TICK)=%d\n", sizeof(TICK));
}

Re: sizeof(TICK) getting 0? [Re: jcl] #461764
08/19/16 16:28
08/19/16 16:28
Joined: Jun 2016
Posts: 29
panz Offline OP
Newbie
panz  Offline OP
Newbie

Joined: Jun 2016
Posts: 29
Hi jcl,

Thanks for quick reply. Your example code worked well with a little modification - without change the code didn't allocate memory to t so it would crash the script. Instead this version worked:

function main()
{
TICK t; t.time = 0;
printf("\nsizeof(TICK)=%d\n", sizeof(TICK));
}


Moderated by  Petra 

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