Thread: "integer operation result is out of range" warning? Can someone explain why?

  1. #1
    Registered User
    Join Date
    Jan 2017
    Posts
    3

    "integer operation result is out of range" warning? Can someone explain why?

    I'm working on an embedded project for an ARM based microcontroller. In one function, I'm casting six 1-byte integers into two words with 0xFFFF to make up the empty space. The lines are below:

    Code:
    report_addr[0] = (0xFFFF)<<16 | p_adv_report->peer_addr.addr[0]<<8 | p_adv_report->peer_addr.addr[1];
    
    report_addr[1] = p_adv_report->peer_addr.addr[2]<<24 | p_adv_report->peer_addr.addr[3]<<16 | p_adv_report->peer_addr.addr[4]<<8 | p_adv_report->peer_addr.addr[5];
    report_addr is an array of uint32.
    peer_addr.addr is an array of uint8.

    My compilers is giving me this warning:
    #61-D: integer operation result is out of range.

    Seems like there's exactly two bytes of data fitting into a 2-byte word. Why is this spitting out a warning? I'd like the project to build without the warning, if possible.

  2. #2
    Old Took
    Join Date
    Nov 2016
    Location
    Londonistan
    Posts
    121
    What 'type' is 0xffff?? Therein lies he issue. Surprised you didn't work that out yourself.

  3. #3
    Registered User
    Join Date
    Jan 2017
    Posts
    3
    Quote Originally Posted by Hobbit View Post
    What 'type' is 0xffff?? Therein lies he issue. Surprised you didn't work that out yourself.
    I declared a uint16 variable with the hex value, then used that in the casting operation. Now, no warning.

    Still learning... Thought I could simply provide the hex value rather than have to make a variable for it.

  4. #4
    Old Took
    Join Date
    Nov 2016
    Location
    Londonistan
    Posts
    121
    You simply needed to change 0xffff to 0xffffU.

    The U tells the compiler that 0xffff is unsigned.

  5. #5
    Registered User
    Join Date
    Jan 2017
    Posts
    3
    That worked, too. Thank you.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 03-12-2011, 06:59 PM
  2. Replies: 14
    Last Post: 11-08-2010, 01:47 AM
  3. Replies: 9
    Last Post: 05-28-2010, 10:11 AM
  4. Replies: 6
    Last Post: 04-05-2010, 09:09 AM
  5. Replies: 2
    Last Post: 05-21-2008, 02:52 PM

Tags for this Thread