If Comparion problem

This is a discussion on If Comparion problem within the C Programming forums, part of the General Programming Boards category; Could someone fix this for me? Error: Constant out of range in comparison (if statement) Code: static word force_reset_countdown = ...

  1. #1
    Registered User
    Join Date
    Apr 2004
    Posts
    28

    If Comparion problem

    Could someone fix this for me?

    Error: Constant out of range in comparison (if statement)

    Code:
    static	word force_reset_countdown = 99;
    
    if( abs( (int)force_reset_countdown-(int)( system_time.second * 1000 + system_time.millisecond ) ) > 120000 )
    {
    	...
    }

  2. #2
    Advanced Novice linucksrox's Avatar
    Join Date
    Apr 2004
    Location
    Michigan
    Posts
    198
    did you try
    Code:
    static int force_reset_countdown = 99;
    ?

  3. #3
    Registered User
    Join Date
    Apr 2004
    Posts
    28
    yes

    same error

  4. #4
    Advanced Novice linucksrox's Avatar
    Join Date
    Apr 2004
    Location
    Michigan
    Posts
    198
    i'm sorry i'm dumb, i meant to ask if you tried static long int or long long int, and since you probably did, did you make sure you changed your type casts too? or remove them...

  5. #5
    Registered User
    Join Date
    Apr 2004
    Posts
    28
    tried what you just said

    same error :/

  6. #6
    Advanced Novice linucksrox's Avatar
    Join Date
    Apr 2004
    Location
    Michigan
    Posts
    198
    i'm guessing you're using #include <math.h> for abs(), but where are you getting system_time.second and system_time.millisecond from? are they your own structures or are you including something else?
    either way it looks strange. int should work just fine for your "word" because the value is always 99. what exactly are you trying to do anyway? i'm really a noob (and i'm a noob to say that) but i guess i can't help
    Last edited by linucksrox; 06-10-2004 at 11:47 PM.

  7. #7
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    What compiler are you using? What does this give you:
    Code:
    printf("sizeof( int ) is %d", sizeof( int ) );
    Quzah.
    Hope is the first step on the road to disappointment.

  8. #8
    Registered User
    Join Date
    Apr 2004
    Posts
    28
    i'm working on an embedded environment

    this is an intel chip

  9. #9
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    And? What is the size of int in your enviornment?

    Quzah.
    Hope is the first step on the road to disappointment.

  10. #10
    Registered User
    Join Date
    Apr 2004
    Posts
    28
    Code:
    sizeof( int )
    gives me 2

    2 bytes?

  11. #11
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Yep. As such, you've got a limit of roughtly 32000. As such, 120000 is just a tad too big.

    Quzah.
    Hope is the first step on the road to disappointment.

  12. #12
    Registered User
    Join Date
    Apr 2004
    Posts
    28
    should i declare them as double?

  13. #13
    Advanced Novice linucksrox's Avatar
    Join Date
    Apr 2004
    Location
    Michigan
    Posts
    198
    no, double is for floating-point, use long or maybe even long long if you want. you can do either long, or long int, whichever you prefer (same with long long or long long int) but long should be sufficient to handle 120000

  14. #14
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    If he only has 2 byte integers, I doubt his compiler or enviornment supports long long, and likely long is the same as int for size. Looks like he gets to rethink the problem.

    Quzah.
    Hope is the first step on the road to disappointment.

  15. #15
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    >and likely long is the same as int for size.

    Why? An int must be able to hold a value in [-32767,32767], but a long must be able to hold a value in [-2147483647,2147483647].
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 05:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 09:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 03:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 07:54 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21