473,670 Members | 2,356 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PPC and atoi

Hi

We've been noticing a problem with atoi conversion on PowerPC.

When we supply value > 2^31-1 to utmost 2^32-1 it doesn't work properly.
What i mean is the converted value when printed using "%u" is not correct.

anybody know a thing or two about this.

regards
senthil
Jul 22 '05 #1
4 1604

"senthil kumar" <se******@roger s.com> wrote in message
news:c8******** *************** ***@posting.goo gle.com...
Hi

We've been noticing a problem with atoi conversion on PowerPC.

When we supply value > 2^31-1 to utmost 2^32-1 it doesn't work properly.
What i mean is the converted value when printed using "%u" is not correct.

anybody know a thing or two about this.

regards
senthil


Not unless you supply a small piece of sample code with the output you get
and the output you expected. It means no-one has to guess what you are
talking about and end up answering a different question from what you had in
mind.

The obvious issue that arises from your description is why you are using %u
on a signed quantity. The way to clear up that issue so that there is no
ambiguity is to POST SOME CODE!

john
Jul 22 '05 #2
senthil kumar wrote:

Hi

We've been noticing a problem with atoi conversion on PowerPC.

When we supply value > 2^31-1 to utmost 2^32-1 it doesn't work properly.
What i mean is the converted value when printed using "%u" is not correct.

anybody know a thing or two about this.

regards
senthil


You are probably bumping against the limits of the signed type on your
architecture.

You need to make sure that your input string is less than or equal to INT_MAX.
Anything over that and you will experience impementation-dependent (undefined)
behavior.

Further, atoi returns an int, %u is for printing unsigned values. You will
need to carefully examine your code to make sure that any (implicit)
conversion/promotion doesn't produce unintended results.
Jul 22 '05 #3
"John Harrison" <jo************ *@hotmail.com> wrote in message news:<c7******* *****@ID-196037.news.uni-berlin.de>...
"senthil kumar" <se******@roger s.com> wrote in message
news:c8******** *************** ***@posting.goo gle.com...
Hi

We've been noticing a problem with atoi conversion on PowerPC.

When we supply value > 2^31-1 to utmost 2^32-1 it doesn't work properly.
What i mean is the converted value when printed using "%u" is not correct.

anybody know a thing or two about this.

regards
senthil


Not unless you supply a small piece of sample code with the output you get
and the output you expected. It means no-one has to guess what you are
talking about and end up answering a different question from what you had in
mind.

The obvious issue that arises from your description is why you are using %u
on a signed quantity. The way to clear up that issue so that there is no
ambiguity is to POST SOME CODE!

john


#include <stdlib.h>

main() {

printf ("%u\n",(unsign ed int)atoi("42949 67295"));

}

basically the code resembles the above sample code. when i run the
above sample code after compiling using gcc it prints out the value
properly however on the PowerPC it truncates.
Jul 22 '05 #4

"senthil kumar" <se******@roger s.com> wrote in message
news:c8******** *************** ***@posting.goo gle.com...
"John Harrison" <jo************ *@hotmail.com> wrote in message

news:<c7******* *****@ID-196037.news.uni-berlin.de>...
"senthil kumar" <se******@roger s.com> wrote in message
news:c8******** *************** ***@posting.goo gle.com...
Hi

We've been noticing a problem with atoi conversion on PowerPC.

When we supply value > 2^31-1 to utmost 2^32-1 it doesn't work properly. What i mean is the converted value when printed using "%u" is not correct.
anybody know a thing or two about this.

regards
senthil


Not unless you supply a small piece of sample code with the output you get and the output you expected. It means no-one has to guess what you are
talking about and end up answering a different question from what you had in mind.

The obvious issue that arises from your description is why you are using %u on a signed quantity. The way to clear up that issue so that there is no
ambiguity is to POST SOME CODE!

john


#include <stdlib.h>

main() {

printf ("%u\n",(unsign ed int)atoi("42949 67295"));

}

basically the code resembles the above sample code. when i run the
above sample code after compiling using gcc it prints out the value
properly however on the PowerPC it truncates.


Truncates to what exactly?

From the C standard section 7.20.1 - [talking about atoi] If the value of
the result cannot be represented, the behaviour is undefined.

Use strtoul instead.

john
Jul 22 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
7436
by: Mike Moum | last post by:
I think there may be a bug in string.atoi and string.atol. Here's some output from idle. > Python 2.3.4 (#2, Jan 5 2005, 08:24:51) > on linux2 > Type "copyright", "credits" or "license()" for more information. > > **************************************************************** > Personal firewall software may warn about the connection IDLE > makes to its subprocess using this computer's internal loopback
6
16044
by: John Smith | last post by:
What's wrong with the use of atoi in the following code? Why do I get the error message: 'atoi' : cannot convert parameter 1 from 'char' to 'const char *' char cBuffer; void PushUnique(int); for(y = 0; y < 9; y++)
5
36421
by: Bansidhar | last post by:
atoi() function seems not to have any support for Hex, octal number. Usually when I read from a text file then it contain number like 0x232 etc. In this case atoi() fells. In case of itoa() there is arrangement of passing the radix. Is there any historical reason that it is not the case with atoi() ? Is there any alternate function in C,C++ for atoi() to take care of all these things ? --Bansidhar
15
29205
by: puzzlecracker | last post by:
does anyone know how to implement this function efficiently?
47
46180
by: sudharsan | last post by:
Hi could you please explain wat atoi( ) function is for and an example how to use it?
13
5759
by: ptq2238 | last post by:
Hi, I have written this code to help me learn C but I'm not sure why gcc - Wall is giving me an error when I compile Basically I want to read in a character then a number and then manipulate the number. I've tried scanf such as scanf("%c%d",&letter,&number); but when I type in say 2 letters instead of 1 letter and 1 number, I get a zero for the 2nd value as it doesn't match what scanf is expecting so I'm
9
4028
by: Would | last post by:
Hey, hopefully one of you can help me... I keep getting an unresolved external 'atoi(char)' and I dont know why.. here is the code #include <iostream> #include <stdlib.h> using namespace std; void main() { int atoi(char c);
11
4250
by: Nezhate | last post by:
Hi all, Can you help me? Why this warning appears in the next simple code ? warning: passing argument 1 of ‘atoi’ makes pointer from integer without a cast. #include <stdio.h> #include <stdlib.h> #include <string.h> int i;
50
5215
by: Bill Cunningham | last post by:
I have just read atoi() returns no errors. It returns an int though and the value of the int is supposed to be the value of the conversion. It seems to me that right there tells you if there was success or not. Am I wrong? Bill
10
4170
by: 66650755 | last post by:
First,thanks for all who have answered my last question. if char string="12345"; how could I convert the string(that is "3") to an int by using atoi? I only want to convert string,not other string. I've written these sentences: int a;
0
8386
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8903
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8592
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6216
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5686
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4213
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2802
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 we have to send another system
2
2044
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1795
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.