problem adding :)

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
GLneo

problem adding :)

Post 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 ???
fraserjgordon

Re:problem adding :)

Post 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
GLneo

Re:problem adding :)

Post by GLneo »

thx!!!, that worked!!!
mystran

Re:problem adding :)

Post 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".
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re:problem adding :)

Post 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
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
mystran

Re:problem adding :)

Post 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.
Post Reply