簡體   English   中英

inttypes.h標頭問題

[英]inttypes.h header issue

nb:由於評論,這個問題已經減少了很多次。 現在下面給出了產生錯誤的最小代碼量。 從此處下載了inttypes.h文件: ffMPEG“找不到inttypes.h” error ),一開始就認為是問題所在。

//tlvlist.c

static int32_t test(somestruct *a);

/* Private method, adds tlv object to the list which contains raw binary data. */
int32_t int32_t test(somestruct *a)
{
    /* Some checks */
    if(a == NULL || bytes == NULL)
        return -1;

    /* Check if list is full */
    if(a->used == MAX_LIST_SIZE)
        return -1;

    /* Index to first free element in the list */
    int iIndex = a->used;

    // ...

    return 0;
}

錯誤:

 tlvlist.c
c:\users\documents\visual studio 2012\projects\tlv list\tlv list\tlvlist.c(21): error C2143: syntax error : missing ';' before 'type'
c:\users\documents\visual studio 2012\projects\tlv list\tlv list\tlvlist.c(23): error C2065: 'iIndex' : undeclared identifier
c:\users\documents\visual studio 2012\projects\tlv list\tlv list\tlvlist.c(24): error C2065: 'iIndex' : undeclared identifier
c:\users\documents\visual studio 2012\projects\tlv list\tlv list\tlvlist.c(28): error C2065: 'iIndex' : undeclared identifier
c:\users\documents\visual studio 2012\projects\tlv list\tlv list\tlvlist.c(29): error C2065: 'iIndex' : undeclared identifier
c:\users\documents\visual studio 2012\projects\tlv list\tlv list\tlvlist.c(32): error C2065: 'iIndex' : undeclared identifier
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

顯然,在MSVS中編譯C文件時,您需要在函數開頭的所有語句之前具有所有變量聲明。 例如:

int32_t Tlvlist_AddRawt(Tlvlist *a, uint8_t type, uint16_t size, const void *bytes)
{
    /* Index to first free element in the list */
    int iIndex;

    /* Some checks */
    if(a == NULL || bytes == NULL)
        return -1;

    iIndex = a->used;

    ...
}

我相信這是舊的C89格式,大多數C編譯器現在都使用C99(或更高版本),這將允許在函數中的任何位置聲明變量。 將文件重命名為CPP是MSVS的另一種選擇,無需將變量聲明移到函數頂部,盡管這可能會引起代碼中的其他問題。

暫無
暫無

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

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