Where is setup() defined in the Arduino code tree?

A recursive grep shows that there exists the declaration "extern void setup( void ) ;" in the Arduino.h file. Other files have the same declaration. But nowhere can I find where setup() actually exists as lines of code. Any clues?

???
You create the setup() function, There are no lines of code until you create the function in your .ino.

Arduino supplies the main() function.
Have a look at main.cpp down in the cores directory.
You will find the main() function that calls you setup() function then has a for loop
that calls your loop() function.

--- bill

setup and loop are in "arduino/hardware/arduino/cores/arduino/main.c"

#include <Arduino.h>

int main(void)
{
	init();

#if defined(USBCON)
	USBDevice.attach();
#endif

	setup();

	for (;;) {
		loop();
		if (serialEventRun) serialEventRun();
	}

	return 0;
}

If you want to avoid the "setup" and "loop" foolishness, simply use this as a code skeleton:

int main (void)
{
    init (); // setup timers, interrupts, etc... (necessary)
    Serial.begin (baudrate); // if needed
//----------------------------------
    normal C and C++ code goes here as usual
//----------------------------------
    while (1); // last line of your code - necessary
}

Or if your code needs to run in an endless loop:

int main (void)
{
    init (); // setup timers, interrupts, etc... (necessary)
    while (1) {
//----------------------------------
    Serial.begin (baudrate); // if needed
    normal C and C++ code goes here as usual
//----------------------------------
    }
}

Hope this helps.