VSCode "Go To Definition" and Find not finding functions and vars

630 views Asked by At

I am using VS Code to do a project where much of the code has already been provided. I am trying to learn how it all works.

Often, both "Go to definition" and control+shift+f returns no results. I would expect valid code structures and functions to have a location somewhere in the file- for example a header or macro.

For example in the below code (just a random snippet), neither searching with control+shift+f nor "go to definition" finds any results for either the addrinfo struct or the getaddrinfo() function (and I want to know why):

int get_listener_socket(char *port)
{
    int sockfd;
    struct addrinfo hints, *servinfo, *p;
    int yes = 1;
    int rv;

    // This block of code looks at the local network interfaces and
    // tries to find some that match our requirements (namely either
    // IPv4 or IPv6 (AF_UNSPEC) and TCP (SOCK_STREAM) and use any IP on
    // this machine (AI_PASSIVE).

    memset(&hints, 0, sizeof hints);
    hints.ai_family = AF_UNSPEC;
    hints.ai_socktype = SOCK_STREAM;
    hints.ai_flags = AI_PASSIVE; // use my IP

    if ((rv = getaddrinfo(NULL, port, &hints, &servinfo)) != 0) {
        fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv));
        return -1;
    }

Note: I opened the entire workspace folder of the project, so everything is there, and I have the C/C++ extension installed. I'm on windows but I'm using GCC and WSL to compile.

My theory is that these structures might be embedded in the compiler as part of a standard, in which case they're not inside files but inside the compiler binary and cannot possibly be found. Learning this will help me make better use of tools, understand how they work and also how C works. Thanks!!

0

There are 0 answers