This is a discussion on Fix sprintf warning within the Coding in General forums, part of the Development/Scripting category; Hi all, I can't figure out how to remove a single warning in my project. Example code: typedef long long ...
|
|||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
|
|||
|
Hi all,
I can't figure out how to remove a single warning in my project. Example code: typedef long long int_64; void write_integer(int x, int y, int_64 i) { char number[35]; sprintf(number, "%u", i); //code that passes number to string write function } When I compile this on linux (gcc with option -Wall) I get the warning: warning: unsigned int format, different type arg (arg 3) The sprintf does work for numbers larger then 32 bit though, the output is correct. Is there a good way to satisfy the compiler? And if there isn't, is there a way to hide a single warning? Thank you, Rick. |
| Sponsored Links | ||
|
|
|
|||
|
Thank you for your reply nixcraft.
This is the complete code that reproduces the warning: example.cpp : Code:
#include <stdio.h>
#include <string.h>
typedef long long int_64;
int main(void)
{
char buffer[51];
int_64 huge_number = 2000000000 * 4;
memset(buffer, 0, 50);
sprintf(buffer, "%u", huge_number);
printf("Result: %s\n", buffer);
return 0;
}
Code:
gcc -lstdc++ -Wall example.cpp -o example Code:
example.cpp: In function `int main()': example.cpp:11: warning: unsigned int format, different type arg (arg 3) Code:
./example Result: 3705032704 Quote:
In this example 2000000000 * 4 should be 8000000000 instead of 3705032704. So it seems the compiler warning is right. That leaves the question: How can I convert a very large number (over 32 bit to a string? |
|
|||
|
Thank you !
It works like a charm. I'm a Delphi programmer for windows. Recently I started to play with C++ and gcc. Linux is way more strict then Windows, which is good IMO. I just encounter a lot of unknowns Thank you for helping. |
![]() |
| Bookmarks |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) |
|
| Thread Tools | |
| Display Modes | |
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| WARNING: add_spec: No major number for SUNW,socal | vasanth | Solaris/OpenSolaris | 0 | 07-26-2006 05:25 PM |
| WARNING: General Protection Faults in these executables-sed | Usagi | Linux software | 7 | 06-23-2006 12:15 PM |
| Script disabling error or warning message output | sweta | Shell scripting | 2 | 04-18-2006 08:24 PM |
| gtk warning cannot open display gnome | Linux software | 1 | 03-14-2006 12:50 PM | |