When should I just use “int” versus more sign-specific or size-specific types?

前端 未结 5 513
眼角桃花
眼角桃花 2021-01-30 06:18

I have a little VM for a programming language implemented in C. It supports being compiled under both 32-bit and 64-bit architectures as well as both C and C++.

I\'m try

5条回答
  •  独厮守ぢ
    2021-01-30 07:15

    Always.

    Unless you have specific reasons for using a more specific type, including you're on a 16-bit platform and need integers greater than 32767, or you need to ensure proper byte order and signage for data exchange over a network or in a file (and unless you're resource constrained, consider transferring data in "plain text," meaning ASCII or UTF8 if you prefer).

    My experience has shown that "just use 'int'" is a good maxim to live by and makes it possible to turn out working, easily maintained, correct code quickly every time. But your specific situation may differ, so take this advice with a bit of well-deserved scrutiny.

提交回复
热议问题