Best Practices: Should I create a typedef for byte in C or C++?

前端 未结 6 1671
情歌与酒
情歌与酒 2021-02-07 05:40

Do you prefer to see something like t_byte* (with typedef unsigned char t_byte) or unsigned char* in code?

I\'m leaning towards

6条回答
  •  梦毁少年i
    2021-02-07 06:09

    If you're using C99 or newer, you should use stdint.h for this. uint8_t, in this case.

    C++ didn't get this header until C++11, calling it cstdint. Old versions of Visual C++ didn't let you use C99's stdint.h in C++ code, but pretty much every other C++98 compiler did, so you may have that option even when using old compilers.

    As with so many other things, Boost papers over this difference in boost/integer.hpp, providing things like uint8_t if your compiler's standard C++ library doesn't.

提交回复
热议问题