sizeof(TICK) getting 0?

Posted By: panz

sizeof(TICK) getting 0? - 08/18/16 19:50

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!
Posted By: jcl

Re: sizeof(TICK) getting 0? - 08/19/16 10:40

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));
}
Posted By: panz

Re: sizeof(TICK) getting 0? - 08/19/16 16:28

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));
}
© 2024 lite-C Forums