Go Down

Topic: problem with multiple tabs (Read 2596 times) previous topic - next topic


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)
Code: [Select]
void setup()

void loop()

and compass.pde
Code: [Select]
#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
Code: [Select]
error: 'readCompass' was not declared in this scope

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


Oct 10, 2008, 04:16 pm Last Edit: Oct 10, 2008, 04:16 pm by mem Reason: 1
I am surprised its random, I didn't think the Arduino IDE creates prototypes for anything except the first tab.
Try adding
[font=Courier New]extern int readCompass(int);[/font]
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...


Oct 10, 2008, 05:51 pm Last Edit: Oct 10, 2008, 05:52 pm by mikalhart Reason: 1
I still cannot find "extern" in the official documentation


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.



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


Oct 11, 2008, 01:41 pm Last Edit: Oct 11, 2008, 01:45 pm by mem Reason: 1
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.

Go Up