473,465 Members | 1,920 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Strange behaviour in different environments

79 New Member
Hello, I have a small program that takes in a number and performs some operations to that number, then returns the value. The relevant code is here:

Expand|Select|Wrap|Line Numbers
  1.       CString codeStr;  
  2.       unsigned __int64 code = (((unsigned __int64)atoi(m_ActEdit) * 9999) + 5) % 1234;
  3.  
m_ActEdit is an entry in an edit box. I'm using atoi to convert it to an int.

After it has been converted to an int it goes through that series of operations to output a number.

Here is the issue. I have that compiled using Visual Studio 6 in XP and using Visual Studio 2005 in Vista.

I used the same input number: 4102182706

The results that I got were different when I ran that same number in both programs:

VS6/XP = 177
VS2005/Vista = 1102

I'm not sure as to why this is happening...Has there been any changes to the way some of the code works (like atoi)? I don't think that the OS has anything to do with it.
Jul 13 '07 #1
4 1707
Darryl
86 New Member
Is one of your machines using a 64 bit processor?

also instead of using atoi, try using _strtoui64
Jul 13 '07 #2
Benny the Guard
92 New Member
I think Darryl is right. The issue is that your # 4102182706 is 32 bits long. atoi returns an int which on most compiler (even 64-bit) is a 32 signed int, meaning you only have 31 bits. So you lose some there. I bet if you use a smaller number you would get he same results.

So you need to use the 64-bit atoi to convert your # to be safe and consistent with your return value.
Jul 14 '07 #3
weaknessforcats
9,208 Recognized Expert Moderator Expert
Also keep in mind that atoi() and it's family of functions are deprecated in C++.
Jul 14 '07 #4
ahammad
79 New Member
Thanks, that works for number that are 19 digits or less.

So I'm assuming that a 64 bit integer is a signed 20 digit number, so an unsigned 19 digit number. Is this right?
Jul 16 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Ben | last post by:
Hi all, I'm trying to figure out how how complex map, filter and reduce work based on the following piece of code from http://www-106.ibm.com/developerworks/linux/library/l-prog.html : ...
24
by: brian.bird | last post by:
Can anyone explain the behaviour of python when running this script? >>> def method(n, bits=): .... bits.append(n) .... print bits .... >>> method(1) >>> method(2)
36
by: Dmitriy Iassenev | last post by:
hi, I found an interesting thing in operator behaviour in C++ : int i=1; printf("%d",i++ + i++); I think the value of the expression "i++ + i++" _must_ be 3, but all the compilers I tested...
3
by: Bruno van Dooren | last post by:
Hi All, i have some (3) different weird pointer problems that have me stumped. i suspect that the compiler behavior is correct because gcc shows the same results. ...
31
by: DeltaOne | last post by:
#include<stdio.h> typedef struct test{ int i; int j; }test; main(){ test var; var.i=10; var.j=20;
6
by: Joseph Geretz | last post by:
Writing an Outlook AddIn with C#. For the user interface within Outlook I'm adding matching pairs of Toolbar buttons and Menu items. All of the buttons and menu items are wired up to send events to...
9
by: Fijoy George | last post by:
Hi all, I am a bit perplexed by the following behaviour of the 'is' comparator False True My understanding was that every literal is a constructure of an object. Thus, the '2.' in 'x = 2.'...
14
by: Bo Yang | last post by:
Following is my code: include <iostream> class Test{ public: Test(){}; void print(){ std::cout << "OK" << std::endl ; }; };
8
by: FBM | last post by:
Hi there, I am puzzled with the behavior of my code.. I am working on a networking stuff, and debugging with eclipse (GNU gdb 6.6-debian).. The problem I am experiencing is the following: ...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.