Order of functions matters?

When I try to compile this example I had to put the freqout() function before loop(), otherwise I got the error:

In function 'void loop()':
error: 'freqout' was not declared in this scope

but according to the arduino reference the order shouldn't matter. Then why does it?

I don't think the Arduino reference is right. Functions should be declared before they are used.

You can put an external declaration to your function near the top of your sketch:extern void freqout(int freq, int t);Then you can put your function anywhere you like since you have told the compiler about the functions's parameters and return value, so it knows how to call it.

The Arduino reference is correct for simple functions in the main sketch or in pde files included as tabs. The build process creates the forward references needed so functions do not need to be declared before they are used. But this does not work for functions that have user defined types or function in c or cpp files and the suggestion to declare references at the top of your sketch may be necessary.

Can you post a small example showing the code that does not compile?

When I copied and compiled Arduino Playground - HomePage it compiled just fine for me. Did you modify the code somehow?

No I didn't, but I noticed that I had a old version of the arduino software, so I downloaded the newest one and then it works without modification. So maybe declaring functions wherever you wan't is a feature added in a newer version. Anyway, thanks for all the help.