diferencia entre stdint.h e inttypes.h


Cuál es la diferencia entre stdint.h e inttypes.h?

Si no se utiliza ninguno de ellos, uint64_t no se reconoce, pero con cualquiera de ellos es un tipo definido.

Author: Tomasz Nurkiewicz, 2011-09-29

2 answers

Ver el artículo de Wikipedia para inttypes.h.

Use stdint.h para un conjunto mínimo de definiciones; utilice inttypes.h si también necesita soporte portátil para estos en printf, scanf, et al.

 15
Author: Ed Staub,
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
2013-04-25 15:18:30

Stdint.h

Incluir este archivo es el "requisito mínimo" si desea trabajar con los tipos enteros de ancho especificado de C99 (es decir, "int32_t", "uint16_t", etc.). Si incluye este archivo, obtendrá las definiciones de estos tipos, de modo que podrá usar estos tipos en declaraciones de variables y funciones y hacer operaciones con estos tipos de datos.

Inttypes.h

Si incluye este archivo, obtendrá todo lo que stdint.h proporciona (porque inttypes.h incluye stdint.h), pero también obtendrá facilidades para hacer printf y scanf (y "fprintf, "fscanf", y así sucesivamente.) con estos tipos de forma portátil. Por ejemplo, obtendrá la macro "PRIu16"para que pueda imprimir un entero uint16_t como este:

#include <stdio.h>
#include <inttypes.h>
int main (int argc, char *argv[]) {

    // Only requires stdint.h to compile:
    uint16_t myvar = 65535;

    // Requires inttypes.h to compile:
    printf("myvar=%" PRIu16 "\n", myvar);  
}
 122
Author: Mikko Östlund,
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
2012-02-06 15:00:40