473,395 Members | 1,941 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

format ‘%X’ expects argument of type ‘unsigned int’, but argument 3 has type 'int *'

giacomomarciani
I don't understand why the piece of code below returns me the error:

warning: format ‘%X’ expects argument of type ‘unsigned int’, but argument 3 has type ‘int *’ [-Wformat]

Expand|Select|Wrap|Line Numbers
  1.     int *v=malloc(10*sizeof(int));
  2.     int i;
  3.     for(i=0;i<10;i++) v[i]=i;
  4.     for(i=0;i<10;i++) printf("v[i]=%+2d &v[i]=%#.10X | 
  5.     *  (v+i)=%+2d (v+i)=%#.10X\n",v[i],&v[i],*(v+i),(v+i));
  6.  
Jan 11 '12 #1
2 15352
donbock
2,426 Expert 2GB
According to the C99 specification, %X takes an unsigned int argument, but you passed &v[i] which is an int*. Your compiler is warning you quite clearly of this mismatch. This mismatch may or may not be significant, it depends on the details of your compiler implementation.

The portable way to print pointer values is with %p. This conversion specifier doesn't accept the # or .10 options.

This forum provides links to two different language references. Curiously, one of these references tells us that %X takes an unsigned int, the other says it takes a signed int. I don't understand this discrepancy. Perhaps this is a difference between C and C++? However, this discrepancy doesn't matter to you -- the warning is warranted in either case.
Jan 11 '12 #2
thank you! solved ;-)
Jan 11 '12 #3

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

Similar topics

3
by: Rakesh | last post by:
In my Python code fragment, I want to write a code fragment such that the minimum element of a tuple is subtracted from all the elements of a given tuple. When I execute the following python...
7
by: Andrew Ward | last post by:
Hi All, Considering the following code: struct A; struct B { std::list<A> l; };
1
by: george doubleu | last post by:
hi, i'm using "gcc version 3.3.3 (Debian)" to compile the program pasted below. I get the two warnings you can see in the remarks. The second warning is perfectly OK for me, but the first one I...
10
by: Frederick Ding | last post by:
Hi, guys! I met a problem: Should I use "int main()" or "int main(void)", is that a kind of "style" problem? And which is the standard C99 recommend? If it's a "style" one, where can I get the...
9
by: haijin.biz | last post by:
I tried the following code and found that the form #include <iostream> using namespace std; int main(int argc, char** argv) { //int a; // error C2466: cannot allocate an array of constant...
2
by: Filip Konvicka | last post by:
Hi all, I wonder whether anyone has seen a workaround for this somewhere, perhaps in Boost or elsewhere... I succeeded using a local type as template argument in MSVC 8.0, but I found out...
2
by: Iain Adams | last post by:
Hi, I am new to python. I have been having trouble using the MysqlDB. I get an error pointing from the line cursor.execute("UPDATE article SET title = %s, text = %s WHERE id = %u",...
1
by: subramanian100in | last post by:
consider template<typename TTest { // ... }; We can have a pointer type as argument to a template class. For example, we can have, int x = 100; Test<int*obj(&x); // assuming a suitable ctor...
105
by: Keith Thompson | last post by:
pereges <Broli00@gmail.comwrites: These types already have perfectly good names already. Why give them new ones? If you must rename them for some reason, use typedefs, not macros. --
15
by: Andreas Eibach | last post by:
.... but I have an unsigned long value in the printf. This warning came when I used gcc 4.x to compile. .... unsigned long offset = 0; .... Well OK, an "easy" way would be instead of printf...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.