472,353 Members | 2,126 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

stdint.h and portability

I wonder how portable the exact width types defined by stdint.h are. I guess
target platforms are not required to actually have all those types, right?
What happens in that case?
Feb 28 '06 #1
4 2239

copx wrote:
I wonder how portable the exact width types defined by stdint.h are. I guess
target platforms are not required to actually have all those types, right?
What happens in that case?


There are certain types in stdint.h that are required, and every
implementation has to provide them. The rest is left for the particular
implementation, and you obviously can't guarentee portability of those.
Have a look in the standard for a list of required types.

Feb 28 '06 #2
"copx" <in*****@invalid.com> wrote:
I wonder how portable the exact width types defined by stdint.h are. I guess
target platforms are not required to actually have all those types, right?
Right. Except that if an implementation provides an (unsigned) integer
type of 8, 16, 32 or 64 bits, no matter what it is or how it is named,
it must also provide the corresponding (u)intN_t typedef in <stdint.h>.
If it does not otherwise provide a particular size integer, it needn't
define the typedef, and typedefs of any other size are completely
optional.
What happens in that case?


They aren't there, and you can use #ifdef INT64_MIN (for example) to
test this. If the implementation provides these optional exact-width
typedefs, it must also #define these macros in <stdint.h>; if it does
not provide a typedef, it must not #define the corresponding macro.

Or you could use (u)int_leastN_t or (u)int_fastN_t, which are required
to exist for N equals 8, 16, 32 and 64, regardless of which other types
exist.

Richard
Feb 28 '06 #3

"Richard Bos" <rl*@hoekstra-uitgeverij.nl> schrieb im Newsbeitrag
news:44****************@news.xs4all.nl...
"copx" <in*****@invalid.com> wrote:
I wonder how portable the exact width types defined by stdint.h are. I
guess
target platforms are not required to actually have all those types,
right?


Right. Except that if an implementation provides an (unsigned) integer
type of 8, 16, 32 or 64 bits, no matter what it is or how it is named,
it must also provide the corresponding (u)intN_t typedef in <stdint.h>.
If it does not otherwise provide a particular size integer, it needn't
define the typedef, and typedefs of any other size are completely
optional.
What happens in that case?


They aren't there, and you can use #ifdef INT64_MIN (for example) to
test this. If the implementation provides these optional exact-width
typedefs, it must also #define these macros in <stdint.h>; if it does
not provide a typedef, it must not #define the corresponding macro.

Or you could use (u)int_leastN_t or (u)int_fastN_t, which are required
to exist for N equals 8, 16, 32 and 64, regardless of which other types
exist.


A very informative reply, thanks!


Feb 28 '06 #4
rl*@hoekstra-uitgeverij.nl (Richard Bos) writes:
"copx" <in*****@invalid.com> wrote:
I wonder how portable the exact width types defined by stdint.h
are. I guess target platforms are not required to actually have all
those types, right?


Right. Except that if an implementation provides an (unsigned) integer
type of 8, 16, 32 or 64 bits, no matter what it is or how it is named,
it must also provide the corresponding (u)intN_t typedef in <stdint.h>.
If it does not otherwise provide a particular size integer, it needn't
define the typedef, and typedefs of any other size are completely
optional.


The {,u}int_{8,16,32,64}_t types are required only if the
implementation provides types of the specified sizes with no padding
bits (and for the signed types, with a two's complement
representation). If an implementation has a 32-bit signed integer
type with no padding bits, but its representation is one's-complement,
int32_t won't be defined (unless there's *also* a two's-complement
type).

The {,u}int_least{8,16,32,64}_t types and the
{,u}int_fast{8,16,32,64}_t type are required.

Types with sizes other than 8, 16, 32, and 64 are optional (and likely
to be rare).

--
Keith Thompson (The_Other_Keith) 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.
Feb 28 '06 #5

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

Similar topics

10
by: Scott David Daniels | last post by:
I am trying to figure out how to get 2.4a2 to build a python extension. GCC 2.2.95 does not have a stdint.h, but 3.2.3 does. These two are the...
6
by: J. Campbell | last post by:
I'm wondering if there are any compelling reasons NOT to use the types defined in stdint.h in c-programms? Please refer to this thread:...
8
by: phil-news-nospam | last post by:
I have some code where I am using certain literal values cast to stdint types like uint32_t, uint64_t, etc. In gcc versions below 3.3 it's working...
20
by: GS | last post by:
The stdint.h header definition mentions five integer categories, 1) exact width, eg., int32_t 2) at least as wide as, eg., int_least32_t 3) as...
93
by: roman ziak | last post by:
I just read couple articles on this group and it keeps amazing me how the portability is used as strong argument for language cleanliness. In my...
11
by: santosh | last post by:
Hello all, Conversion macros along the name of INT8_C, INT16_C etc, are defined in stdint.h to convert their argument into suitable...
10
by: Mikail Dellovich | last post by:
stdint.h exists on my Solaris 10(sparc) system but not on my Solaris 9(sparc) system. How do I rectify this situation? Thanks
130
by: euler70 | last post by:
char and unsigned char have specific purposes: char is useful for representing characters of the basic execution character set and unsigned char is...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python...

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.