Different outputs in vc6 & vs2008 with same code(typecasting). Help
-
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
-
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
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
-
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
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
-
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
-
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
Is there any similar solution as for c# - http://wkfry.spaces.live.com/blog/cns!BF2CFFE0D35B3B70!233.entry[^]
Priya Sundar