How do you find stuff in a C/C++ program?

I am trying to study how the ESP8266 code implements interrupts.

The principal code seems to be in the file core_esp8266_wiring_digital.c

Just picking, as an example, these two lines from the code

GPC(pin) &= ~(0xF << GPCI);//INT mode disabled
GPIEC = (1 << pin); //Clear Interrupt for this pin

I’m guessing the GPC() is a macro defined somewhere and GPIEC is a variable defined somewhere.

Neither of these seems to be defined in any of the flles included in this file

#include "wiring_private.h"
#include "pins_arduino.h"
#include "c_types.h"
#include "eagle_soc.h"
#include "ets_sys.h"

How is one supposed to find the file in which those things are defined?

I am asking this as a general question in the hope that someone will explain the process for finding the definitions. While finding the file for those specific definitions would help, I suspect there are dozens of others that I will need to find.

This is something I have always struggled with in C/C++. When I was using Ruby I rarely had any trouble finding where functions etc were defined.


The answer is "with difficulty". Finding those things requires understanding something about the (rather complex) Arduino build system. For non-AVR boards, like the ESP, the "hardware dependent" files will be found somewhere down the "C:\Users\username\AppData\Local\aruino15\packages path.

Ray L.

find . -name "*" | xargs grep GPCis my go-to solution.

Finding the right . in the first place may be the tricky bit

There are numerous greps available. The one from Borland / Embarcadero does well on Windows. Like @AWOL I often use grep in such situations.

The Visual Studio IDE will sometimes work. It's fairly aggressive at building its browser database.

A good map file can help. Some linkers include module information with symbols. At least then you know which module (file).

A solid state drive is a godsend in such situations. I can search (grep) my entire harddrive in less than 30 seconds.

Also openGrok is a useful tool.

Thanks guys. I will try GREP (or openGrok). I was hoping there was a more logical way.

Update. I just used the Linux search accessory and found what I needed in no time. I guess all solutions are blindingly obvious when you know them :slight_smile:

Thanks again.


Or a google on #define GPC esp8266 gets you to github quickly (or a github search)

For large software projects (like the Arduino IDE itself), there are the Gnu ID Utils and eTags. These are faster than grep, but unlikely to climb up through the
"system level" include files unless you build their databases very carefully.

Running the compile command with -E to generate pre-processor output will give you a list of all the included files, though it may not be recognizable enough to find a particular definition. (It's more useful for finding things to use as "." in those grep/find commands...)

I have found what I needed for now - and thanks.

One problem I noticed while searching was that one search term came up with 78 files that contained the word. That's not a lot better than telling me it is "somewhere on my hard disk" :slight_smile:

It'd be nice if there was a hard-disk equivalent of Google to prioritize the found files.


I use Eclipse IDE and there is it very easy with F3 to go right to the declaration of the symbol. It opens the source file and selects the file in the source file tree.