Maxime Barbeau
Hi.
I have the following code:
uint32_t quadlet = 0x12345678;
printf("quadlet = %08X\n", quadlet);
my compiler give me the following warning: unsigned int format, uint32_t
arg (arg 2)
Is there any formtat I can use? %08uX ?
thanks
Maxime
Nov 14 '05 #1
Subscribe Reply
10 32599
- 1
- 2
- >
Tom St Denis
Maxime Barbeau wrote:
Hi.I have the following code:
uint32_t quadlet = 0x12345678;
printf("quadlet = %08X\n", quadlet);my compiler give me the following warning: unsigned int format, uint32_t
arg (arg 2)Is there any formtat I can use? %08uX ?
%lx
Tom
Nov 14 '05 #2
Chris
On Fri, 13 Aug 2004 15:11 GMT, Tom St Denis <to********@iah u.ca> wrote:
Maxime Barbeau wrote:I have the following code:
uint32_t quadlet = 0x12345678;
printf("quadlet = %08X\n", quadlet);my compiler give me the following warning: unsigned int format, uint32_t
arg (arg 2)Is there any formtat I can use? %08uX ?
%lx
No, %lx is not completely correct. %lx expects an unsigned long.
Although unsigned long and uint32_t have the same representation on many
systems, there's absolutely no requirement for them to. We do know that
unsigned long is at least 32 bits, so a more proper method would be to
use %lx and cast the argument to unsigned long. That way, if unsigned
long is, say, 64 bits, printf() won't grab an extra 32 bits of junk off
the stack (or whatever method your implementation happens to use for
argument passing).
Chris
Nov 14 '05 #3
CBFalconer
Maxime Barbeau wrote:
I have the following code:
uint32_t quadlet = 0x12345678;
printf("quadlet = %08X\n", quadlet);my compiler give me the following warning: unsigned int format,
uint32_t arg (arg 2)Is there any formtat I can use? %08uX ?
Using uint32_t requires #include <stdint.h> and a C99 compiler
system. You probably don't have either.
--
Chuck F (cb********@yah oo.com) (cb********@wor ldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home .att.net> USE worldnet address!
Nov 14 '05 #4
Keith Thompson
"Maxime Barbeau" <ma************ @mindready.com> writes:
I have the following code:
uint32_t quadlet = 0x12345678;
printf("quadlet = %08X\n", quadlet);my compiler give me the following warning: unsigned int format, uint32_t
arg (arg 2)Is there any formtat I can use? %08uX ?
Where is uint32_t defined? If you're using C99, uint32_t is a typedef
in <stdint.h>; it's probably equivalent to one of unsigned short,
unsigned int, or unsigned long (most likely the latter in your case).
But you don't know which, so you can't safely use a format for one of
the predefined types.
The C99 header <inttypes.h> provides macros that expand to printf
formats for various types, including uint32_t, but they're ugly.
But you know that uint32_t is exactly 32 bits, and you know that
unsigned long is at least 32 bits, so you can do this:
uint32_t quadlet = 0x12345678;
printf("quadlet = %08lX\n", (unsigned long)quadlet);
--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #5
Jack Klein
On Fri, 13 Aug 2004 19:07:34 GMT, CBFalconer <cb********@yah oo.com>
wrote in comp.lang.c:
Maxime Barbeau wrote:
I have the following code:
uint32_t quadlet = 0x12345678;
printf("quadlet = %08X\n", quadlet);my compiler give me the following warning: unsigned int format,
uint32_t arg (arg 2)Is there any formtat I can use? %08uX ?
Using uint32_t requires #include <stdint.h> and a C99 compiler
system. You probably don't have either.
That's just plain bullschildt, Chuck.
Using uint32_t requires a <stdint.h> header, or equivalent. Any
conforming C90 compiler that has the right size integer types with 2's
complement representation, and that is the overwhelming majority of
them, will work just fine with a properly written <stdint.h> file, for
whatever subset of C99 integer types that they support and they are
not hard at all to write. They're just typedefs, after all.
Every conforming C89/C90 implementation can support all of the
''least'' and ''fastest'' up to 32 bits, if not 64 bits.
And what conforming implementation have you ever actually used that
did not provide an exact-width 32-bit integer type with no trap
representations and using 2's complement for the signed version?
I've written several (subset) stdint.h headers for a variety of
embedded 16-bit, 32-bit, and DSPs. Heck, the one that comes with
ARM's ADS 1.1 or 1.2 development tools compiles and works perfectly
with Visual C++ 6.
The corresponding <inttypes.h> header with its macros for printf() and
scanf() is more work, but it is also possible and I've done it.
Many compilers, even though they do not support all of C99, include a
working <stdint.h> and <inttypes.h>, even quite a few available for
free download. All of the 32-bit ones I know of support the 64-bit
types as well. Here's a list of compilers that I know have these
headers:
-- Borland's free C++BuilderX
-- mingw
-- gcc
-- lcc-win32
-- Codewarrior for Windows
-- ARM ADS
-- IAR for ARM
....and I've made subset headers that worked on platforms like TI DSPs
and 16 micros. Heck, I could write subset headers in half an hour or
less for an 8051, if I couldn't get out of never using on again.
So come off your high horse, you do not need C99 for using and
printing uint32_t, all you need is a pair of headers that can be used
quite well in C89/C90, or in some K&R 1 implementations for that
matter. It requires no language features at all, just typedefs and
the automatic string concatenation for the <inttypes.h> macros that
wasn't universal until C89.
--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.l earn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Nov 14 '05 #6
CBFalconer
Jack Klein wrote:
CBFalconer <cb********@yah oo.com> wrote in comp.lang.c:Maxime Barbeau wrote:
I have the following code:
uint32_t quadlet = 0x12345678;
printf("quadlet = %08X\n", quadlet);my compiler give me the following warning: unsigned int format,
uint32_t arg (arg 2)Is there any formtat I can use? %08uX ?
Using uint32_t requires #include <stdint.h> and a C99 compiler
system. You probably don't have either.That's just plain bullschildt, Chuck.
Using uint32_t requires a <stdint.h> header, or equivalent. Any
conforming C90 compiler that has the right size integer types with 2's
complement representation, and that is the overwhelming majority of
them, will work just fine with a properly written <stdint.h> file, for
whatever subset of C99 integer types that they support and they are
not hard at all to write. They're just typedefs, after all.
Am I wrong that stdint.h did not exist in C90? M. Barbeau
certainly did not show any definitions for that term. Isn't
uint_32 implementation optional even in C99?
--
Chuck F (cb********@yah oo.com) (cb********@wor ldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home .att.net> USE worldnet address!
Nov 14 '05 #7
Keith Thompson
CBFalconer <cb********@yah oo.com> writes:
Jack Klein wrote:CBFalconer <cb********@yah oo.com> wrote in comp.lang.c:Maxime Barbeau wrote:I have the following code:
uint32_t quadlet = 0x12345678;
printf("quadlet = %08X\n", quadlet);my compiler give me the following warning: unsigned int format,
uint32_t arg (arg 2)Is there any formtat I can use? %08uX ?
Using uint32_t requires #include <stdint.h> and a C99 compiler
system. You probably don't have either.That's just plain bullschildt, Chuck.
Using uint32_t requires a <stdint.h> header, or equivalent. Any
conforming C90 compiler that has the right size integer types with 2's
complement representation, and that is the overwhelming majority of
them, will work just fine with a properly written <stdint.h> file, for
whatever subset of C99 integer types that they support and they are
not hard at all to write. They're just typedefs, after all.Am I wrong that stdint.h did not exist in C90? M. Barbeau
certainly did not show any definitions for that term. Isn't
uint_32 implementation optional even in C99?
uint32_t is mandatory in C99 if (and only if) the implementation
provides a 32-bit two's complement integer type with no padding bits.
(The standard's wording is a trifle ambiguous, but I think there's a
DR clarifying it.) But there are C90-compatible implementations of
<stdint.h>.
Note that the original poster got an error message for the printf
format but not for the declaration of quadlet, so there must have been
a declaration of uint32_t somewhere.
--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #8
Maxime Barbeau
Hello every one.
Thanks for your help
I am writing a program that will go on an embedded system.
I am using VxWorks for x86 and the PPC family.
This code is shared with QNX and will probably go under other OSs and CPUs.
The #include <inttypes.h> or <stdint.h> is certainly included in the header
I use.
After reading the posts, I guess I can use printf("quadlet : %08lX\n",
quadlet);
Maxime
"Maxime Barbeau" <ma************ @mindready.com> wrote in message
news:lR******** ***********@web er.videotron.ne t...
Hi.I have the following code:
uint32_t quadlet = 0x12345678;
printf("quadlet = %08X\n", quadlet);my compiler give me the following warning: unsigned int format, uint32_t
arg (arg 2)Is there any formtat I can use? %08uX ?
thanks
Maxime
Nov 14 '05 #9
Ben Pfaff
"Maxime Barbeau" <ma************ @mindready.com> writes:
I have the following code:
uint32_t quadlet = 0x12345678;
printf("quadlet = %08X\n", quadlet);
Actually, you want:
printf("quadlet = %"PRIx32"\n" , quadlet);
assuming you have a working <inttypes.h>.
--
"The way I see it, an intelligent person who disagrees with me is
probably the most important person I'll interact with on any given
day."
--Billy Chambless
Nov 14 '05 #10
- 1
- 2
- >
This thread has been closed and replies have been disabled. Please start a new discussion.
Similar topics
1 1828 Help needed: Printing unicode characters in user defined format by: Pekka Niiranen |last post by: Hi there, how can I write out Python Unicode character's hexadecimal value in generic format? I need to loop thru characters in Unicode string and store each character in format \U+hhhh, where hhhh is the value of unicode character in hexadecimal? For example string: Python |
6 13859 Printing an unsigned char by: Enrico `Trippo' Porreca |last post by: Suppose I wanted to print an unsigned char (in hex). Should I say: unsigned char x = 0x12; printf("%X\n", x); or printf("%X\n", (unsigned) x); C / C++ |
10 22831 hexadecimal to float conversion by: pavithra.eswaran |last post by: Hi, I would like to convert a single precision hexadecimal number to floating point. The following program seems to work fine.. But I do not want to use scanf. I already have a 32 bit hexadecimal number and would like to convert it into float. Can anyone tell me how to do it? int main() { float theFloat; C / C++ |
1 2881 sending hexadecimal data to cryptographic hash functions by: Fernando Barsoba |last post by: Hi all, First of all, I'd like to thank you "Skarmander" and "Flash Gordon" for the help they provided me: Skarmander's algorithm and Flash's modifications helped me a lot. Here's the problem I had and the question which I still have regarding that problem: I tried to send a hex string to a function that performed message C / C++ |
8 18670 How to read a Hexadecimal file ? by: Vijay |last post by: Hi , I am doing a small project in c. I have a Hexadecimal file and want to convert into ascii value. (i.e., Hexadecimal to Ascii conversion from a file). Could anyone help me? Thanks in adv. C / C++ |
7 19240 Convert Binary String to Hexadecimal by: elliotng.ee |last post by: I have a text file that contains a header 32-bit binary. For example, the text file could be: %%This is the input text %%test.txt Date: Tue Dec 26 14:03:35 2006 00000000000000001111111111111111 11111111111111111111111111111111 00000000000000000000000000000000 11111111111111110000000000000000 C / C++ |
14 2940 Problem printing Hexadecimal by: abhishekkarnik |last post by: Hi, I am trying to read an exe file and print it out character by character in hexadecimal format. The file goes something like this in hexadecimal 0x4d 0x5a 0x90 0x00 0x03 .... so on When I read it into my array " two_bytes" which has 16 characters in total, I get each of these values read correctly, but when I attempt printing them out, it prints something like this: 0x4d 0x5a 0xffffff90 0x00 0x03 .... so on. I have no clue why. How... C / C++ |
6 14773 HEXADECIMAL to STRING by: Andrea |last post by: Hi, suppose that I have a string that is an hexadecimal number, in order to print this string I have to do: void print_hex(unsigned char *bs, unsigned int n){ int i; for (i=0;i<n;i++){ printf("%02x",bs); } } C / C++ |
6 16921 convert decimal to hexadecimal number by: sweeet_addiction16 |last post by: hello Im writin a code in c... can sum1 pls help me out in writing a c code to convert decimalnumber to hexadecimal number.The hexadecimal number generated has to be an unsigned long. C / C++ |
9735
What is ONU? 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, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of... General |
9610 Changing the language in Windows 10 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,... Windows Server |
10672
Problem With Comparison Operator <=> in G++ 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... C / C++ |
10143
Discussion: How does Zigbee compare with other wireless protocols in smart home applications? by: tracyyun |last post by: Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some... General |
1 7687
Access Europe - Using VBA to create a class based on a table - Wed 1 May 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... Microsoft Access / VBA |
5710 Windows Forms - .Net 8.0 by: adsilva |last post by: A Windows Forms form does not have the event Unload, like VB6. What one acts like? Visual Basic .NET |
1 4358 transfer the data from one system to another through ip address 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 C# / C Sharp |
2 3886
How to add payments to a PHP MySQL app. by: muto222 |last post by: How can i add a mobile payment intergratation into php mysql website. PHP |
3 3030
Comprehensive Guide to Website Development in Toronto: Expert Insights from BSMN Consultancy 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... General |