Go Down

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

randName

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()
{
 readCompass(1);
 Serial.begin(9600);
}

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


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?

mem

#1
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.



randName

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?

mem

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

randName

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...

mikalhart

#5
Oct 10, 2008, 05:51 pm Last Edit: Oct 10, 2008, 05:52 pm by mikalhart Reason: 1
Quote
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

randName

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

mem

#7
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.

mellis

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.

randName

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.

mellis

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.

randName

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