简体   繁体   中英

Determining where a type is defined

I am working on a rather large code base that has a bit of the #ifdef magic going on. I'm looking at one file and trying to determine where a type is defined. Unfortunately, it includes many file, which include many files, which include many files, etc. some of which define macros that affect which definitions you might use. The structure is sufficiently complicated that after 10 minutes worth of grepping and following the include chains, I still have no idea which definition is being used. I recall that visual studio has a nice feature where I can right click on the type and it will show where the type is defined. Is there an equivalent nice tool for linux that reads make files, etc? I'm sure there is, but I still just use vim + grep for my development environment.

With complicated defines and dependencies this feature doesn't always work in Visual Studio either.

Solution: ask your compiler to dump the code after it was preprocessed, ask it to print #line and #file directives too. Search through the resulted file for your type, then look at the closest #file directive to see where it came from.

(In GCC you can use the -E switch)

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