Thread: "overflow in implicit constant conversion"

  1. #1
    Registered User
    Join Date
    Jun 2016
    Posts
    2

    "overflow in implicit constant conversion"

    Hello. Absolute beginner.

    I'm following the code in this video
    https://www.youtube.com/watch?v=oVo0NVGUsU0
    I worked out the code exactly as is by the end of the video. My result is different. Of all the videos I followed, this is the only time my code is producing a different result than his.

    The full code is
    Code:
    #include <iostream>
    #include <limits.h>
    
    using namespace std;
    
    int main() {
    
        int value = -54656;
        cout << value << endl;
    
        cout << "Max int value: "<< INT_MAX << endl;
        cout << "Max int value: "<< INT_MIN << endl;
    
        long int lValue = 2345325345345;
        cout << lValue << endl;
    
        short int sValue = 23434;
        cout << sValue << endl;
    
        cout << "Size of int: " << sizeof(int) << endl;
        cout << "Size of short int: " << sizeof(short int) << endl;
    
        unsigned int uValue = 2342343;
        cout << uValue << endl;
    
        return 0;
    }
    My result in the console is
    Code:
    -54656
    Max int value: 2147483647
    Max int value: -2147483648
    273201729
    23434
    Size of int: 4
    Size of short int: 2
    2342343
    His result is
    Code:
    Max int value: 2147483647
    Max int value: -2147483648
    2345325345345
    23434
    Size of int: 4
    Size of short int: 2
    2342343
    I also have "overflow in implicit constant conversion" here:

    Code:
        long int lValue = 2345325345345;
    Why is my result different than his?

    I'm using Eclipse Luna Service Release 2 (4.4.2), MingGW GC 78

  2. #2
    Guest
    Guest
    What hardware are you running on? Add this line to your program:
    Code:
    cout << "Size of long int" << sizeof(long int) << endl;
    If it prints 4, then you have your answer – it's likely 8 byte on his machine.

    Edit: Actually, this might be OS dependent (I wasn't aware), check this out.
    Last edited by Guest; 06-18-2016 at 04:42 PM.

  3. #3
    Registered User
    Join Date
    Jun 2016
    Posts
    2
    I get 4.
    Yeah, he's on a Mac, I'm on a PC.

    Alright. I was more concerned that this could be a serious problem down the road. Thanks!122

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    There are actually types that have a specific width. Those are way better to use than int, long, short, etc IMO.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 6
    Last Post: 09-30-2015, 08:49 AM
  2. Replies: 8
    Last Post: 10-25-2012, 12:08 PM
  3. Replies: 2
    Last Post: 09-12-2006, 04:50 AM
  4. "itoa"-"_itoa" , "inp"-"_inp", Why some functions have "
    By L.O.K. in forum Windows Programming
    Replies: 5
    Last Post: 12-08-2002, 08:25 AM
  5. "CWnd"-"HWnd","CBitmap"-"HBitmap"...., What is mean by "
    By L.O.K. in forum Windows Programming
    Replies: 2
    Last Post: 12-04-2002, 07:59 AM

Tags for this Thread