Using ssize_t vs int

后端 未结 3 803
陌清茗
陌清茗 2020-12-08 19:22

Code

I\'ve got a function which I can write in one of four possible ways:

    int do_or_die(int retv         


        
3条回答
  •  情书的邮戳
    2020-12-08 19:45

    You can use int or long int data types, however ssize_t is a system data type that should be used for cross-platform portability. The fundamental types (such as 'int') can be different sizes on different implementations. Usually what happens is the system type (in this case ssize_t) takes advantage of C's typedef feature so that the machine-specific data type size is used, e.g. typedef signed ssize_t (this is part of SUSv3 standard data types). It is good practice to use system data types, where possible, when implementing any kind of system-level programming.

    For a more detailed description refer to The Linux Programming Interface (Michael Kerrisk)

提交回复
热议问题