Search code examples
c++visual-studio-2017typedefforward-declarationfunction-definition

Why does VS2017 warn "Function definition not found" for functions forward declared with input typedef'd but defined with original?


I'm trying to imitate how CURL seems to implement CURL struct internally as Curl_easy such that API users use struct name CURL, and the API internally references CURL as Curl_easy.

This is done by having

typedef struct Curl_easy CURL

in curl/curl.h and then having

CURL_EXTERN CURL *curl_easy_init(void);

and

struct Curl_easy *curl_easy_init(void)

in curl/easy.h and easy.c, respectively.

So I copied that idea and made a small example which should do the same thing:

typedef struct IntStruct IS;

IS* initializeIS();
void countUpIS( IS* is );

struct IntStruct
{
    int i;
};

IntStruct* initializeIS()
{
    IntStruct* is = new IntStruct;
    is->i = 0;
    return is;
}

void countUpIS( IntStruct* is )
{
    is->i++;
}

#include <iostream>
using namespace std;

int main( int argc, char* argv[] )
{
    IS* is = initializeIS();
    countUpIS( is );
    cout << is->i << endl;

    return 0;
}

Which leaves the users of those functions initializeIS() and countUpIS() use struct name "IS" but developers of those functions refer to it as "IntStruct".

This code compiles and runs fine, but VS2017 seems to green-underline countUpIS as "Function definition for 'countUpIs' not found".

Any insights to why is this the case? Something perfectly legal but just not parsed well within VS2017?


Solution

  • Some programmer dude provided the answer in a comment:

    The parser used by IntelliSense inside Visual Studio is not the same parser used by the actual compiler. Therefore there are cases (like your apparently) where the two differs.