简体   繁体   中英

inttypes.h header issue

nb: This question has been reduced many times, due to comments. 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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