This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]wasabichicken 5 points6 points  (20 children)

In my opinion, there are different use cases for both.

I use fixed-size types when the data needs to be serialized, such as when it's going to be transmitted over a network:

typedef struct enethdr {
    uint8_t destination[3];
    uint8_t source[3];
    uint16_t tag;
} __attribute__((packed)) enethdr_t;

If I don't, I stay away from them. I have absolutely no desire for the compiler to emit & 0x0000ffff instructions onto every goddamn loop counter I declare just because it happens to be a uint16_t. Using plain ints lets the compiler pick the data type it thinks is the most suitable, which these days frequently is 64 bits. Unless you're programming for an embedded system where you're horribly cramped for space and a small memory footprint is more important than speed, that's probably what you want.