0

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

gcr
  • 443
  • 2
  • 5
  • 14
  • Thanks but where would they be stored in Windows or Linux? For example in a .dll file? I have not found it explained well in discussions of headers. The implementation (def) might be elsewhere other than the header, but where? – gcr Dec 20 '20 at 19:26
  • 1
    Thanks! I think I know what the issue is. I'm using Windows but compiling with WSL (Windows Subsystem for Linux). When I #include the windows headers you suggest, VS Code brings me to the defs, otherwise it does nothing. I think somehow gcc inside WSL has access to things VS Code doesn't, namely the sys/socket.h. – gcr Dec 20 '20 at 19:45

0 Answers0