user1561108
user1561108

Reputation: 2747

How to find out where a C struct is declared?

I am trying to add logging to the web proxy Polipo and as part of this need to log the url request in the following function following line:

httpClientRequest(HTTPRequestPtr request, AtomPtr url)

From compilation I see that AtomPtr is a struct of type _Atom but I cannot find where this is defined so that I can reference the text of the url in a log statement. What is the canonical method of looking up struct definitions in C code?

Upvotes: 1

Views: 1360

Answers (4)

jitheshKuyyalil
jitheshKuyyalil

Reputation: 51

I was able to look up the definition of a structure MenuType by

grep -Rwn --include \*.h "struct MenuType"

This post helped me.

Upvotes: 0

saygins
saygins

Reputation: 85

you can search AtomPtr like this and see where AtomPtr is defined

typedef struct _Atom {
    unsigned int refcount;
    struct _Atom *next;
    unsigned short length;
    char string[1];
} AtomRec, *AtomPtr;

Upvotes: 2

Right leg
Right leg

Reputation: 16730

Unfortunately, as far as I know, you cannot do this from the source code in C.
If you are working on Linux, and if your sources are all in the src/ directory:

$ find src/ -name ".*\.h" | xargs grep -e "struct _Atom"

Upvotes: 1

tuhin panda
tuhin panda

Reputation: 31

If you are working on Linux, then grep the struct keyword in the current directory to see the definition of it in the file.

Upvotes: 0

Related Questions