cdeclarationstdint

Predeclaration of C stdint types


When I tried to declare some types defined in stdint.h a conflict with /usr/include/bits/stdint-uintn.h:24:19 predeclaration occurs

typedef struct __uint8_t uint8_t;

Error message:

/usr/include/bits/stdint-uintn.h:24:19: error: conflicting types for ‘uint8_t’
   24 | typedef __uint8_t uint8_t;
      |                   ^~~~~~~
In file included from ../src/server/connection.c:1:
../src/server/connection.h:4:26: note: previous declaration of ‘uint8_t’ was here
    4 | typedef struct __uint8_t uint8_t;

How can I predeclare those types in my header files to avoid circular dependencies?


Solution

  • #include <stdint.h> is the correct way to declare these types. Any other approach is undefined and/or non-portable.

    There can never be a circular dependency issue with standard headers.