problem with multiple tabs

This seems to be a random error, after checking the Playground (Build Process)...

I have 2 files in a sketch, namely
Test.pde (no extension)

void setup()
{
  readCompass(1);
  Serial.begin(9600);
}

void loop()
{
  Serial.println(readCompass(0));
  delay(100);
}

and compass.pde

#define compassPin 2
int calOffset=0, heading=0;
int readCompass(int init=0)
{
  unsigned long duration=pulseIn(compassPin,HIGH);
int temp=(duration*360)/36990;
  if(init==1){calOffset=temp; return temp;} else {return ((360+temp-calOffset)%360);}
}

And I get the error

error: 'readCompass' was not declared in this scope

I am using 0012 on Vista. Any idea what is going on?

I am surprised its random, I didn't think the Arduino IDE creates prototypes for anything except the first tab.
Try adding
extern int readCompass(int);
to test.pde and see if that fixes it.

Works like a charm. Thanks for the quick response.

If it is not random I should have found it. I still cannot find "extern" in the official documentation. Shouldn't this be included somewhere?

You may not need the extern keyword, try removing extern and see if just the following is enough:
int readCompass(int);

It appears that it does work

So the only problem is that there are no prototypes for anything not in the first tab. A rather trivial one...

I still cannot find "extern" in the official documentation

rand--

C++ is a very large, powerful language. Besides "extern", it has many facets which the Arduino website couldn't feasibly document. I think the site is designed to get beginners started without spooking them away with reams of C++ minutiae. The hope is that as your needs grow, you'll turn to other canonical resources to pick up the details.

Mikal

An obscure C/++ construct? Then I shall stop complaining. It took me quite a while to find (boolean?A:B) also.

That's because boolean is an arduino construct, C++ has bool.

I have my doubts about the effectivness of using the Arduino to learn C++. It can be done, but it seems diametrically opposed to the whole concept of hiding the complexities of programming that gave rise to the Arduino.

If I remember right, the problem is that the code that auto-generates function prototypes doesn't yet handle default arguments. It should generate prototypes for functions in all .pde tabs.

After checking, I think that is the only explanation. I tried readCompass() without a default argument and it worked without the prototype.

And apparently I should declare default arguments in the prototype according to the thread here.

Rather interesting. I never had to do this in C++. I had everything in one place and nothing was needed, but decided to switch to multitabbed programming since I wouldn't want to hunt for code.

Yeah, you shouldn't have to that, but my function prototype generation code isn't perfect. It's in PdePreprocessor.java if you're curious.

Ouch. Java is not in my realm, so I don't think I can help any.

Well, the one good thing about prototypes now is that it helps me keep track of what other functions I have on the other tabs. I think I will have many.