Thread: Trying to (Still) understand overflow

  1. #1
    Registered User
    Join Date
    Mar 2020
    Posts
    6

    Trying to (Still) understand overflow

    Hi,

    I'm new to the forum. I came across these forums after a google search into C integer overflow. I found the following post;

    how to handle integer overflow in C

    Which is helping me understand overflow. To a point.

    Thanks to Dave_Sinkula for the code examples

    I've read that unsigned integer overflow is not UB. Does this mean that testing for overflow of unsigned integers is the same across all implementations?

    The post that bought be to these forums deals with multiplication of integers.. Are the rules the same say if I was using the pow function with a and b?
    eg:
    Code:
    pow(a,b)
    I've also come across the following post which I'm trying to get my head around;
    Definitive Guide To Integer Overflow.

    Apologies if my questions are asinine or pedestrian. I am just learning C and this topic seems to confuse a lot of neophyte programmers like myself.

    Thanks.

  2. #2
    Registered User
    Join Date
    Dec 2017
    Posts
    943
    I've read that unsigned integer overflow is not UB. Does this mean that testing for overflow of unsigned integers is the same across all implementations?
    It says that unsigned integers are supposed to function the same across all implementations. It doesn't say anything about "testing for overflow of unsigned integers". In fact, you might say that unsigned ints never "overflow". They just wrap around, like an odometer, in either direction.

    Signed integers can be implemented differently on different systems. They do not generally "wrap around" in a sane way. For the common two's-complement representation of signed integers, adding 1 to the highest positive value "wraps around" to the lowest negative value.

    The post that bought be to these forums deals with multiplication of integers.. Are the rules the same say if I was using the pow function with a and b?
    The pow function takes floating point values, which are a different kettle of fish entirely.
    If you want the truth to stand clear before you, never be for or against. - Sent-ts'an

  3. #3
    Registered User
    Join Date
    Mar 2020
    Posts
    6
    Hi John,

    Thank you for the feedback.. I think it's clear that I do not grasp the topic. I'll go back over the forum posts. What I am stuck on.. I want to test for integer overflow before it happens... I know that after the fact is UB... I think I need to go over the original post that bought me here..

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Under/Overflow you do handle them
    By ali.franco95 in forum C Programming
    Replies: 5
    Last Post: 10-07-2011, 12:58 AM
  2. Preventing overflow
    By 843 in forum C++ Programming
    Replies: 7
    Last Post: 03-18-2011, 11:18 AM
  3. int overflow
    By nimitzhunter in forum C++ Programming
    Replies: 9
    Last Post: 12-12-2010, 01:36 AM
  4. overflow...?
    By Tool in forum C Programming
    Replies: 10
    Last Post: 12-23-2009, 03:41 PM
  5. Overflow
    By valthyx in forum C Programming
    Replies: 14
    Last Post: 06-01-2009, 04:41 PM

Tags for this Thread