Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c which include contains function

Tags:

c

include

I received a large code file, that I didn't write. There's a function being used in that code that I want to use myself in a separate code file. Is there a quick and simple way to find which of the (many) includes in the original code file makes this function available?

like image 818
giladrv Avatar asked Jan 29 '26 18:01

giladrv


2 Answers

The fastest way is usually to grep for the function name (pro tip: use grep -rw to search recursively and for whole-word matches only). That assumes you have some idea which directories the header file may be in.

If that won't work, you can preprocess the file. With GCC that's the -E option instead of -c. This will output what the actual compiler sees, after #includes are resolved. Then you can easily search in the preprocessed file for the function declaration and look above that for which file it came from.

like image 82
John Zwinck Avatar answered Jan 31 '26 07:01

John Zwinck


This completely depends on your developmnet environment. I often use ack tool (consider it as "better grep" for programmers) for that purpose, beside that I know that some IDEs have "go to definition" or "go to declaration" feature, so you can directly look for function's definition or its prototype.

like image 33
Grzegorz Szpetkowski Avatar answered Jan 31 '26 07:01

Grzegorz Szpetkowski



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!