Pages: [1]   Go Down
Author Topic: uint8_t, uint16_t, int, unsigned int  (Read 11237 times)
0 Members and 1 Guest are viewing this topic.
The Netherlands (Rotterdam)
Offline Offline
Full Member
Karma: 1
Posts: 169
Arduino rocks!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


I am trying to modify a library at the moment. The library uses:

uint8_t and uint16_t

Until now I am only used of using the int and unsigned int (data types as described in the arduino reference).

Why should you use uint8_t and uint16_t instead of int unsigned int? is it good practice?

Thanks in advance.

Offline Offline
Karma: 0
Posts: 49
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This should explain everything.

As it says, using those methods make your code more portable because it can be reused on other platforms because they might have a different idea of what int and others mean.

Offline Offline
Faraday Member
Karma: 8
Posts: 6240
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Using the Stdint types does help to make code portable and it is good practice for writing libraries.

But I suggest you stick to the arduino documented types for sketch code. Almost all the Arduino abstractions that are designed to make code easier to read and write are not portable to other platforms and using the more esoteric Stdint types would only serve to confuse many beginners.

Pages: [1]   Go Up
Jump to: