What is the purpose of the size_t and ssize_t commands in C?

4

What is the purpose of the size_t and ssize_t commands? What kind of data do they represent?

size_t minhavariavel1;
ssize_t minhavariavel2;
    
asked by anonymous 16.12.2015 / 01:21

2 answers

5

Technically they are not commands. These are data types.

size_t is essentially the same as an unpinned int that is used to store the return of a sizeof operation.

ssize_t a flagged integer and is used in situations where same representation of the data size that can return a negative value in case of failure. It is out of the ANSI C standard, so avoid using it.

Although they are integers, it is ideal to keep them separate. Each type with its function, gives more semantics to the die and avoids future problems if it needs to make any changes.

    
16.12.2015 / 01:29
4

size_t is set in the default C (in stddef.h ). ssize_t is the signed version of size_t , but is defined in a POSIX extension, so it may not exist on all platforms.

size_t represents the size of something (quantity), and how unsigned does not represent negative values. The ssize_t , being signed , can also represent such values. For example, the result of a function can be the size of the parameter (if it is zero / positive) or an error code (if it is negative).

    
16.12.2015 / 01:27