¿Se definen tipos como uint32, int32, uint64, int64 en cualquier encabezado stdlib?


A menudo veo código fuente usando tipos como uint32, uint64 y me pregunto si deberían ser definidos por el programador en el código de la aplicación o si están definidos en un encabezado lib estándar.

¿Cuál es la mejor manera de tener estos tipos en el código fuente de mi aplicación?

 78
Author: philix, 2011-05-16

4 answers

El C99 stdint.h define estos:

  • int8_t
  • int16_t
  • int32_t
  • uint8_t
  • uint16_t
  • uint32_t

Y, si la arquitectura los soporta:

  • int64_t
  • uint64_t

Hay varios otros tipos enteros en stdint.h también.

Si está atascado sin un entorno C99, probablemente debería proporcionar sus propios tipos y usar los C99 de todos modos.

El uint32 y uint64 (es decir, sin el sufijo _t) son probablemente específicos de la aplicación.

 112
Author: mu is too short,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-06-10 15:01:49

Esos tipos enteros están todos definidos en stdint.h

 10
Author: GWW,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-05-16 04:47:40

Si está utilizando C99 solo incluya stdint.h. POR cierto, los tipos de 64 bits están allí si el procesador los soporta.

 2
Author: BiGYaN,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-05-16 06:19:39

El interrogador realmente preguntó sobre int16 (etc) en lugar de (feo) int16_t (etc).

No hay encabezados estándar - ni ninguno en la carpeta /usr/include/ de Linux que los defina sin el "_t".

 -1
Author: Steve,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-04-06 14:05:59