View unanswered posts | View active topics It is currently Tue Oct 21, 2014 12:09 am






Reply to topic  [ 7 posts ] 
Writing a "task main()" 
Author Message
Site Admin
Site Admin

Joined: Wed Jan 24, 2007 10:44 am
Posts: 439
Location: Pittsburgh, PA
Post Writing a "task main()"
Tip: When using task main(), you only have to type it once!

Be very careful with using the correct characters such as parenthesis "()", and curly braces "{}".

The proper format should be:

Code:
task main()
{

}

_________________
Vu Nguyen
Software Training Development Team | Webmaster
Need more support? Use the ROBOTC Ticketing system

Robotc.net| Robomatter Store | Robotics Academy | CS2N


Tue Mar 18, 2008 10:21 am
Profile
Novice

Joined: Thu Apr 17, 2008 6:04 am
Posts: 70
Location: Plymouth, Indiana, USA
Post 
Hello,
Slowly I've been learning C and RobotC. I just noticed some of the sample RobotC programs have "task main ()" at the beginning and some don't have "task main () at all. I just tried my own simple program and it didn't seem to matter if I used "task main ()" or not.
What is the criteria for when "task main ()" must be used? How can it sometimes not be needed?

For example: The RobotC sample programs; "NXT Hello World", "Execution Speed Test", and "NXT Hello World Expanded" don't have the "task main()". They are 12, 496, and 33 lines of code respectively.

Thanks.

_________________
Dad (Dave) and Adam


Thu Apr 17, 2008 6:12 am
Profile
Rookie

Joined: Sat Oct 25, 2008 3:47 pm
Posts: 38
Post Re: Writing a "task main()"
I'm probably not the best person to try and answer your question seeing I'm a total noob at this, but I seem to remember that if a program has a "task main()" that task will be the first to be executed, no matter where it is located in the program. If it doesn't have a "task main()", the first task the compiler finds (reading from top to bottom) will be the first one to be executed.

Can anyone please confirm if I'm right?


Sat Oct 25, 2008 6:57 pm
Profile
Expert
User avatar

Joined: Sat Sep 20, 2008 12:16 pm
Posts: 106
Location: Curently fighting aliens on P3X-828
Post Re: Writing a "task main()"
A task main() is normally the first function, in this case a task, that the compiler reads. If there is no task main, it reads form top to bottom. I also program in C++, and with C++ you use int main(), with the parameters in the parentheses if used. RobotC thus looks like this:
Code:
#include "JoystickDrivers.c"

task main()
{
    while(true)
    {
        getJoystickSettings(joystick);
        if(joy1Btn(1))
        {
            PlaySound(soundbeepbeep);
        }
    }
}

while C++ looks like this:
Code:
#include <iostream>
#include <string>

using namespace std;

string password;

int main()
{
    while(password != "admin")
    {
                   cout << "enter password" << endl;
                   cin >> password;
                   if(password == "admin")
                   {
                               cout << "Access Granted" << endl;
                   }
                   else
                   {
                       cout << "Access Denied" << endl;
                       cout << "Password Hint: Strongest" << endl;
                   }
    }
    system("PAUSE");
    return 0;
}

Either way, the * main(parameters if used) is the first function to be read.

_________________
:downloading:
Sorry, your program could not be downloaded. Please reboot your computer.
FTC Team #2959 Team Smash Bros CLICK HERE.(or click www)
Quote:
What the world needs is more geniuses with humility, there are so few of us left.

Agreed


Sun Oct 26, 2008 5:35 pm
Profile WWW
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3225
Location: Rotterdam, The Netherlands
Post Re: Writing a "task main()"
I think the examples without the task main() that are shipped with RobotC are really counter intuitive and terrible examples of how to program RobotC. It sets a bad precedent. I think it would be good to rewrite them with a task main().

Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Sun Oct 26, 2008 6:42 pm
Profile WWW
Rookie

Joined: Sat Jul 30, 2011 10:03 am
Posts: 7
Post Operating system in NXT brick
which kind of operating system in NXT brick ?
what is RobotC (its application or operating system to NXT brick)


Tue Sep 06, 2011 2:27 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3225
Location: Rotterdam, The Netherlands
Post Re: Writing a "task main()"
It's not really a full operating system but a small firmware. ROBOTC is both the programming language -and- the programming environment.

- Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Tue Sep 06, 2011 2:34 pm
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 7 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


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.