Page 1 of 1
problem adding :)
Posted: Mon Jun 27, 2005 1:51 pm
by GLneo
hi, ok, in my timer i simply add (++) to a variable but 1 statment later it continues to be 0 the code:
Code: Select all
double long ticks = 0;
int sys_time = 0;
void clock()
{
ticks++;
if(ticks >= 9)
{
sys_time++;
ticks = 0;
}
putint(sys_time); putchar(' '); putint(ticks); putchar('\n');
}
i know clock is getting called becouse it prints, but ticks never gets bigger, so it must be a heap problem?
p.s. in djgpp, how do you zero out heap ???
Re:problem adding :)
Posted: Mon Jun 27, 2005 2:14 pm
by fraserjgordon
Are you only checking "ticks" using putint() or are you actually examining the value in memory? It might be that the error is in putint() rather than the counter. If you aren't sure, do something like putchar('S') inside the if-statement to see if it ever runs.
The other possibility is that using 64-bit integers requires support code and so doesn't increment properly. As you are only ever counting up to 9 anyway, try using a normal int.
HTH,
Fraser
Re:problem adding :)
Posted: Mon Jun 27, 2005 3:12 pm
by GLneo
thx!!!, that worked!!!
Re:problem adding :)
Posted: Tue Jun 28, 2005 7:10 am
by mystran
What is "double long" btw? Is is really an integer at all? AFAIK gcc usually calls 64-bit (on ia-32 anyway) integers "long long".
Re:problem adding :)
Posted: Tue Jun 28, 2005 7:42 am
by Brendan
Hi,
mystran wrote:
What is "double long" btw? Is is really an integer at all? AFAIK gcc usually calls 64-bit (on ia-32 anyway) integers "long long".
For GCC a "double long" is considered a 96 bit floating point value - in reality it's an 80 bit (10 byte) floating point value with 16 bits of padding.
As for "long long", I'm waiting for SSE4 and 128 bit integers in IA-32
.
Cheers,
Brendan
Re:problem adding :)
Posted: Tue Jun 28, 2005 10:27 am
by mystran
Another point I'd like to mention: newer GCC releases (3.x and later) are quite aggressive with eliminating redundant loads/stores, so if you plan to read the tick-counter from another thread (which GCC doesn't know anything about) you probably need to declare the variable as "volatile" as in "this variable is read/written from multiple concurrent threads, and therefore caching it in a register will cause problems".
I'm not sure if DJGPP was ever updated to new enough GCC, but I'd use "volatile" anyway where necessary, because adding those later is VERY painful. Possibly even more painful than adding spinlocks for SMP protection.