0

Ever since I started programming in C I have known/seen everyone to use the following convention when declaring variables using typedefs as shown below:

   int32_t *data_value;
   const int16_t *Order_Of_Mag;
   uint16_t min_change;
   uint8_t  eeprom_save_flag;

I understand part of the reason is for portability between different architectures. Does anyone know when and/or what standard dictates this method for declaration?

Also what's the recommended method for dealing with standard library (stdio.h) functions that require the use of char, given that a char is neither uint8_t nor int8_t (see example functions below)

sscanf(const char *format)
int atio(const char *s)

Thanks in advance

maguirre
  • 399
  • 4
  • 20
  • 1
    Everyone is doing it!? Are you doing embedded programming by any chance? – NPE Dec 13 '12 at 17:46
  • 1
    Check out [Chris Lutz](http://stackoverflow.com/a/1725901/418715) answer about `uint8_t` as well as the accepted answer. – Joe Dec 13 '12 at 17:58
  • @NPE Apologies I should have said "Everyone I know in the embedded world" – maguirre Dec 13 '12 at 18:16

1 Answers1

1

The only standards that I know of that require you to use such typedefs are project/company specific coding conventions. Those coding conventions then also specify exactly which typedefs (or even macros) to use, so it might be UINT32 instead of uint32_t that you must use


As for the choice between char, uint8_t or int8_t, the default should be to use char for character data (i.e. strings and characters) and uint8_t or int8_t for small numbers.

Bart van Ingen Schenau
  • 15,488
  • 4
  • 32
  • 41