Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Different outputs in vc6 & vs2008 with same code(typecasting). Help

Different outputs in vc6 & vs2008 with same code(typecasting). Help

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestion
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Priya_Sundar
    wrote on last edited by
    #1

    Hi, Below is the code for which i get different outputs when compiled in vc6 and vs2008. Why is it happening? Any comments will be helpful.

    double x2 = 4294967036;
    
    int i = 0;
    
    i=(int)x2;
    
    CString str;
    
    str.Format(\_T("%d == %d"),i,INT\_MAX);
    
    AfxMessageBox(str); 
    

    Output in vc6: -260 == 2147483647 Output in VS2008: -2147483648 == 2147483647 I can see that as the value is greater than max limit, its trying to display the max value. But I guess the typecasting is not exactly working in VS2008. How to make the typecasting work?

    Priya Sundar

    D P 3 Replies Last reply
    0
    • P Priya_Sundar

      Hi, Below is the code for which i get different outputs when compiled in vc6 and vs2008. Why is it happening? Any comments will be helpful.

      double x2 = 4294967036;
      
      int i = 0;
      
      i=(int)x2;
      
      CString str;
      
      str.Format(\_T("%d == %d"),i,INT\_MAX);
      
      AfxMessageBox(str); 
      

      Output in vc6: -260 == 2147483647 Output in VS2008: -2147483648 == 2147483647 I can see that as the value is greater than max limit, its trying to display the max value. But I guess the typecasting is not exactly working in VS2008. How to make the typecasting work?

      Priya Sundar

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      Priya_Sundar wrote:

      But I guess the typecasting is not exactly working in VS2008.

      It looks as though VS6 is the one that is not working. If you have a signed integer with a value of 231, every time you increment it, the value will get smaller until it reaches -231.

      Priya_Sundar wrote:

      How to make the typecasting work?

      What are you trying to do?

      "One man's wage rise is another man's price increase." - Harold Wilson

      "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

      "Man who follows car will be exhausted." - Confucius

      P 1 Reply Last reply
      0
      • D David Crow

        Priya_Sundar wrote:

        But I guess the typecasting is not exactly working in VS2008.

        It looks as though VS6 is the one that is not working. If you have a signed integer with a value of 231, every time you increment it, the value will get smaller until it reaches -231.

        Priya_Sundar wrote:

        How to make the typecasting work?

        What are you trying to do?

        "One man's wage rise is another man's price increase." - Harold Wilson

        "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

        "Man who follows car will be exhausted." - Confucius

        P Offline
        P Offline
        Priya_Sundar
        wrote on last edited by
        #3

        Basically I have huge old code with the way vc6 works. We then migrated it to vs2008. So the same old code seems to produce different results. So we are looking for some solution.

        Priya Sundar

        1 Reply Last reply
        0
        • P Priya_Sundar

          Hi, Below is the code for which i get different outputs when compiled in vc6 and vs2008. Why is it happening? Any comments will be helpful.

          double x2 = 4294967036;
          
          int i = 0;
          
          i=(int)x2;
          
          CString str;
          
          str.Format(\_T("%d == %d"),i,INT\_MAX);
          
          AfxMessageBox(str); 
          

          Output in vc6: -260 == 2147483647 Output in VS2008: -2147483648 == 2147483647 I can see that as the value is greater than max limit, its trying to display the max value. But I guess the typecasting is not exactly working in VS2008. How to make the typecasting work?

          Priya Sundar

          P Offline
          P Offline
          Priya_Sundar
          wrote on last edited by
          #4

          []https://connect.microsoft.com/VisualStudio/feedback/details/98977/rtcc-fails-to-catch-overflows-in-double-integer-conversions?wa=wsignin1.0#tabs[^]

          Priya Sundar

          1 Reply Last reply
          0
          • P Priya_Sundar

            Hi, Below is the code for which i get different outputs when compiled in vc6 and vs2008. Why is it happening? Any comments will be helpful.

            double x2 = 4294967036;
            
            int i = 0;
            
            i=(int)x2;
            
            CString str;
            
            str.Format(\_T("%d == %d"),i,INT\_MAX);
            
            AfxMessageBox(str); 
            

            Output in vc6: -260 == 2147483647 Output in VS2008: -2147483648 == 2147483647 I can see that as the value is greater than max limit, its trying to display the max value. But I guess the typecasting is not exactly working in VS2008. How to make the typecasting work?

            Priya Sundar

            P Offline
            P Offline
            Priya_Sundar
            wrote on last edited by
            #5

            Is there any similar solution as for c# - http://wkfry.spaces.live.com/blog/cns!BF2CFFE0D35B3B70!233.entry[^]

            Priya Sundar

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups