View unanswered posts | View active topics It is currently Tue Sep 30, 2014 8:14 pm






Reply to topic  [ 10 posts ] 
Forward Declaring Tasks 
Author Message
Professor
User avatar

Joined: Sat May 18, 2013 1:24 pm
Posts: 272
Location: Olympia, WA
Post Forward Declaring Tasks
Is it possible to forward declare tasks? There are some small tasks (such as continually waving a servo) that I'd like to define at the end of my program. Can I say something like
Code:
task waveFlag();

task main() {
    StartTask(waveFlag);
}

task waveFlag() {
    // do stuff
}

and expect it to work? Because the compiler won't respond, but it doesn't give me errors either. And I don't feel like writing/learning a multitasking library right now. :) If this is illegal, I'll probably put the task definitions in a header file.

_________________
FTC Team 6424, the 'Oly Cow - Chief programmer.
FRC Team 4450, Olympia Robotics Federation (ORF).

and also quadrotors. Quadrotors!


Tue Nov 05, 2013 10:09 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: Forward Declaring Tasks
Ernest3.14 wrote:
Is it possible to forward declare tasks? There are some small tasks (such as continually waving a servo) that I'd like to define at the end of my program. Can I say something like
Code:
task waveFlag();

task main() {
    StartTask(waveFlag);
}

task waveFlag() {
    // do stuff
}

and expect it to work? Because the compiler won't respond, but it doesn't give me errors either. And I don't feel like writing/learning a multitasking library right now. :) If this is illegal, I'll probably put the task definitions in a header file.

Why do you need to forward declare? What's wrong with putting the entire waveFlag task first? Do you have a circular reference?


Wed Nov 06, 2013 12:15 am
Profile
Professor
User avatar

Joined: Sat May 18, 2013 1:24 pm
Posts: 272
Location: Olympia, WA
Post Re: Forward Declaring Tasks
I'll never have to look at the task ever again, and it's annoying to scroll down to my main code. I'm working on laptops (without mice!), and there's a couple hundred lines to scroll through :P

_________________
FTC Team 6424, the 'Oly Cow - Chief programmer.
FRC Team 4450, Olympia Robotics Federation (ORF).

and also quadrotors. Quadrotors!


Wed Nov 06, 2013 12:53 am
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: Forward Declaring Tasks
Put your task in a .h file and #include it!


Wed Nov 06, 2013 1:36 am
Profile
Professor
User avatar

Joined: Sat May 18, 2013 1:24 pm
Posts: 272
Location: Olympia, WA
Post Re: Forward Declaring Tasks
So that didn't fix the issue--I'm still troubleshooting. So far the forward declaration doesn't seem to be the issue. So if anyone from the future is reading this, you can forward declare tasks. Just like normal functions.

EDIT: The problem seems to be declaring a `const float` and then using that variable as part of an assignment.

_________________
FTC Team 6424, the 'Oly Cow - Chief programmer.
FRC Team 4450, Olympia Robotics Federation (ORF).

and also quadrotors. Quadrotors!


Mon Nov 11, 2013 1:19 am
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: Forward Declaring Tasks
Would you show the problem line of code? If you declared the variable as const, I hope you did not use it on the left side of the assignment operator.


Mon Nov 11, 2013 1:41 am
Profile
Professor
User avatar

Joined: Sat May 18, 2013 1:24 pm
Posts: 272
Location: Olympia, WA
Post Re: Forward Declaring Tasks
No, of course not. :) I take that all back. It was declaring a float (doesn't need to be const) as global, and then using it to initialize a local variable. E.g.:
Code:
float foo = 3.14;

task main() {
   float bar = 2.17;
   float baz = bar-foo;
}

_________________
FTC Team 6424, the 'Oly Cow - Chief programmer.
FRC Team 4450, Olympia Robotics Federation (ORF).

and also quadrotors. Quadrotors!


Mon Nov 11, 2013 12:53 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: Forward Declaring Tasks
Ernest3.14 wrote:
No, of course not. :) I take that all back. It was declaring a float (doesn't need to be const) as global, and then using it to initialize a local variable. E.g.:
Code:
float foo = 3.14;

task main() {
   float bar = 2.17;
   float baz = bar-foo;
}

I compiled your code above. Except for a minor warning, I don't have any issue with it. The warning was:
Quote:
**Info***:'baz' is written but has no read references

which is correct.
What error did you see?


Mon Nov 11, 2013 1:26 pm
Profile
Professor
User avatar

Joined: Sat May 18, 2013 1:24 pm
Posts: 272
Location: Olympia, WA
Post Re: Forward Declaring Tasks
Really? I don't get any errors. But when I open the file again, RobotC crashes.

_________________
FTC Team 6424, the 'Oly Cow - Chief programmer.
FRC Team 4450, Olympia Robotics Federation (ORF).

and also quadrotors. Quadrotors!


Mon Nov 11, 2013 3:25 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: Forward Declaring Tasks
Ernest3.14 wrote:
Really? I don't get any errors. But when I open the file again, RobotC crashes.

robotc crashes repeatedly sometimes. When that happens, you need to clear the registry to stop it from crashing. I don't have robotc with me but there should be a menu choice allowing you to clear the registry.


Mon Nov 11, 2013 4:45 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 10 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.