Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Whats the difference between UInt8 and uint8_t

Tags:

c++

c

objective-c

What is the differnce between UInt8 and uint8_t, or UInt16 and unit16_t?

What does the _t imply?

like image 239
user1845029 Avatar asked Jun 05 '13 10:06

user1845029


2 Answers

In C99 the available basic integer types (the ones without _t) were deemed insufficient, because their actual sizes may vary across different systems.

So, the C99 standard includes definitions of several new integer types to enhance the portability of programs. The new types are especially useful in embedded environments.

All of the new types are suffixed with a _t and are guaranteed to be defined uniformly across all systems.

For more info see the fixed-width integer types section of the wikipedia article on Stdint.

like image 82
vdbuilder Avatar answered Sep 28 '22 23:09

vdbuilder


The main difference is that the uintX_t types are standard C defined by C99 and later while UIntX is not. This has implications for how portable the code is. Code using uintX_t types can be compiled on any standard C compiler without any other dependencies. Code that uses UIntX on the other hand, must either define those types itself, or depend on some library or framework that does so.

I don't think Objective-C as such defines any extra integer types, but it may well be that your framework (Coacoa, OpenStep?) does so. If your code makes no sense outside of the framework, use what's idiomatic in the framework context. Otherwise try to stick to the standard types.

like image 24
harald Avatar answered Sep 28 '22 23:09

harald