Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
4 registered members (VoroneTZ, dr_panther, TedMar, vicknick), 833 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 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: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

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