简体   繁体   English

inttypes.h标头问题

[英]inttypes.h header issue

nb: This question has been reduced many times, due to comments. nb:由于评论,这个问题已经减少了很多次。 Below now is presented minimum amount of code which generated the error. 现在下面给出了产生错误的最小代码量。 inttypes.h file was downloaded from here: ffMPEG "inttypes.h not found" error ), which was thought to be the issue in the beginning. 从此处下载了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;
}

errors: 错误:

 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 ==========

Evidently, when compiling a C file in MSVS you need to have all variable declarations at the start of the function before any statement. 显然,在MSVS中编译C文件时,您需要在函数开头的所有语句之前具有所有变量声明。 For example: 例如:

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;

    ...
}

I believe this is old C89 format and most C compilers now use C99 (or greater) which would permit variable declarations anywhere in the function. 我相信这是旧的C89格式,大多数C编译器现在都使用C99(或更高版本),这将允许在函数中的任何位置声明变量。 Renaming the file as CPP is another option for MSVS without moving the variable declarations to the top of a function, though it may raise other issues in the code. 将文件重命名为CPP是MSVS的另一种选择,无需将变量声明移到函数顶部,尽管这可能会引起代码中的其他问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM