簡體   English   中英

C stdint 類型的預聲明

[英]Predeclaration of C stdint types

當我嘗試聲明在stdint.h中定義的某些類型時,會發生與/usr/include/bits/stdint-uintn.h:24:19預聲明的沖突

typedef struct __uint8_t uint8_t;

錯誤信息:

/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;

如何在我的 header 文件中預先聲明這些類型以避免循環依賴?

這是因為stdint.h包含bits/stdint-uintn.h ,其中

typedef struct __uint8_t uint8_t;

被定義為。

您不應該重新定義uint8_t 對我來說,解決方案是刪除

typedef struct __uint8_t uint8_t;

從您的文件../src/server/connection.c

您有什么理由需要自己重新定義它嗎?

#include <stdint.h>是聲明這些類型的正確方法。 任何其他方法都是未定義和/或不可移植的。

標准標頭永遠不會存在循環依賴問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM