"Properly sized types like int32_t", forsooth! Those abominations
are precisely the wrong way to achieve portability over a wide range
of systems or over the long term.
I dare say you show clue-lessness
I shall be dead and buried when
the 64->128 change hits, but people will discover their error then,
oh, yes, they will!
No, int32_t and friends became NECESSARY when the 32 to 64 wave hit,
a simple example, and audio wave header spec:
#ifndef _WAVE_HEADER_H_
#define _WAVE_HEADER_H_
typedef struct
{ /* header for WAV-Files */
uint8_t main_chunk[4]; /* 'RIFF' */
uint32_t length; /* length of file */
uint8_t chunk_type[4]; /* 'WAVE' */
uint8_t sub_chunk[4]; /* 'fmt' */
uint32_t length_chunk; /* length sub_chunk, always 16 bytes */
uint16_t format; /* always 1 = PCM-Code */
uint16_t modus; /* 1 = Mono, 2 = Stereo */
uint32_t sample_fq; /* Sample Freq */
uint32_t byte_p_sec; /* Data per sec */
uint16_t byte_p_spl; /* bytes per sample, 1=8 bit, 2=16 bit (mono) 2=8 bit, 4=16 bit (stereo) */
uint16_t bit_p_spl; /* bits per sample, 8, 12, 16 */
uint8_t data_chunk[4]; /* 'data' */
uint32_t data_length; /* length of data */
} wave_header;
#endif /* _WAVE_HEADER_H_ */
Now in the OLD version it used 'int', and when 'int' changed size again (in bits) of
course the whole structure was different.
I am so happy with uint8_t, if you are closer to hardware you will understand why.
You may claim that that is an 'external' interface, so be it,
but it is nice to be constantly aware of the width of variables.
int32_t should be used ONLY for external interfaces, and it doesn't
help with them because it doesn't specify the endianness or overflow
handling. And not all interfaces are the same. All internal types
should be selected as to their function - e.g. array indices, file
pointers, hash code values or whatever - so that they will match the
system's properties. As in Fortran, K&R C etc.
The _t is great, as it is just that, that creates portability:
From libc.info:
- Function: int fseeko (FILE *STREAM, off_t OFFSET, int WHENCE)
This function is similar to fseek' but it corrects a problem with
fseek' in a system with POSIX types. Using a value of type ong
int' for the offset is not compatible with POSIX. fseeko' uses
the correct type f_t' for the OFFSET parameter.
Note that I was involved in both the C89 and C99 standardisation
process; and the BSI didn't vote "no" for no good reason.
So, when we move to 128 bits (if ever), at least my programs should still work.
You know, I do not like people being pedantic, maybe because they often are right,
and make your code look silly or bad.
I try to code in the lowest subset common denominator of C, avoiding exotic constructs.
That goes a long way, so far most compilers swallow it, but ultimately libc with libc.info
is my reference.
The whole world will soon move to Unix and gcc anyways, even John Larkin will learn C...
<disclaimer>
This posting contains forward looking statements that may or may not be true.