View unanswered posts | View active topics It is currently Sun Oct 26, 2014 2:30 am






Reply to topic  [ 12 posts ] 
How do you access methods #include files? 
Author Message
Rookie

Joined: Fri Feb 17, 2012 10:39 pm
Posts: 3
Post How do you access methods #include files?
I know how to reference files with #include, but how do I access functions from within the included files? I was thinking it might be similar to java, where it's something like filename.methodname(), but I didn't have time to test in robotics today. I have the following code:
Code:
#include "RedIsolation.c"
#include "BlueIsolation.c"
#include "RedInteraction.c"
#include "BlueInteraction.c"

Each file has a method with the same name inside. For example, "RedIsolation.c" has a RedIsolation() method inside.

-Ujomin


Fri Feb 17, 2012 10:45 pm
Profile
Senior Roboticist
User avatar

Joined: Wed Sep 28, 2011 10:13 pm
Posts: 630
Location: If I told you, I'd have to kill you.
Post Re: How do you access methods #include files?
Ujomin wrote:
I know how to reference files with #include, but how do I access functions from within the included files? I was thinking it might be similar to java, where it's something like filename.methodname(), but I didn't have time to test in robotics today. I have the following code:
Code:
#include "RedIsolation.c"
#include "BlueIsolation.c"
#include "RedInteraction.c"
#include "BlueInteraction.c"

Each file has a method with the same name inside. For example, "RedIsolation.c" has a RedIsolation() method inside.

-Ujomin


I believe it's just like calling a function that's already in the program. That's how it is in RobotC for NXT, and I don't see why it would be different for Cortex.

_________________
A.K.A. inxt-generation
Self-proclaimed genius, and future world dominator.
My Brickshelf Folder
"Don't they teach recreational mathematics anymore?" - The Tenth Doctor
Bow down to Nikola Tesla, King of the Geek Gods.


Fri Feb 17, 2012 11:50 pm
Profile WWW
Moderator
Moderator
User avatar

Joined: Tue Sep 14, 2010 9:19 pm
Posts: 496
Post Re: How do you access methods #include files?
Using #include is pretty much the same as copying and pasting the code in that file into your current file. So you can just call the functions as if they were defined in your current file.

_________________
sudo rm -rf /


Sat Feb 18, 2012 2:50 am
Profile
Rookie

Joined: Fri Feb 17, 2012 10:39 pm
Posts: 3
Post Re: How do you access methods #include files?
miki wrote:
Ujomin wrote:
Each file has a method with the same name inside. For example, "RedIsolation.c" has a RedIsolation() method inside.
Hi Ujomin,
Split your program into several files is a smart idea ;-) .
:idea: You are not forced to have 1 function 1 file.


Thanks Miki. I got scolded by my fellow team members for not "object orienting" our code enough, so I'm trying to be on the safe side. I'll probably condense it later, but I would like to keep it as clear for them as possible.

Thanks again!


Sat Feb 18, 2012 8:19 am
Profile
Creator
Creator

Joined: Fri Feb 09, 2007 9:21 am
Posts: 615
Post Re: How do you access methods #include files?
Ujomin wrote:
miki wrote:
Ujomin wrote:
Each file has a method with the same name inside. For example, "RedIsolation.c" has a RedIsolation() method inside.
Thanks Miki. I got scolded by my fellow team members for not "object orienting" our code enough, so I'm trying to be on the safe side. I'll probably condense it later, but I would like to keep it as clear for them as possible.

One function per file is not the same as object orienting. I've never run across this philosophy in my decades of developing commercial applications.


Sat Feb 18, 2012 10:23 am
Profile
Rookie

Joined: Fri Feb 17, 2012 10:39 pm
Posts: 3
Post Re: How do you access methods #include files?
I don't usually do it when I'm using Java, VB, C#, etc, and I'm not really sure why I did it yesterday. We fixed that today, along with noticing some other issues.
Also, it wasn't just one method per file, but only one method had to be accessed externally.

_________________
Code:
public static void main(String[] args) {
    Programmer ujomin = new Programmer("Ujomin");
    while (true) {
        ujomin.write(Language.JAVA);
    }
}


Sat Feb 18, 2012 8:30 pm
Profile
Creator
Creator

Joined: Fri Feb 09, 2007 9:21 am
Posts: 615
Post Re: How do you access methods #include files?
Ujomin wrote:
Also, it wasn't just one method per file, but only one method had to be accessed externally.

"Data hiding" or "function hiding" in this case makes sense as is one of the elements of good programming practice.


Sun Feb 19, 2012 5:50 am
Profile
Moderator
Moderator
User avatar

Joined: Tue Sep 14, 2010 9:19 pm
Posts: 496
Post Re: How do you access methods #include files?
Is it actually possible to do "encapsulation" in ROBOTC?

_________________
sudo rm -rf /


Sun Feb 19, 2012 11:23 am
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3227
Location: Rotterdam, The Netherlands
Post Re: How do you access methods #include files?
No, it isn't possible. Only good programmer practice can help you in this regard, the language does not enforce anything.

- 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 Feb 19, 2012 12:22 pm
Profile WWW
Moderator
Moderator
User avatar

Joined: Tue Sep 14, 2010 9:19 pm
Posts: 496
Post Re: How do you access methods #include files?
miki wrote:
Hi Magicode,
C or RobotC compilers can't prevent an unauthorized access to some data by unauthorized function.
However, in RobotC like in C or non object oriented language, you can use coding conventions to simulate/emulate encapsulation.
It's efficient if the developer strictly follows those rules.
Some code examples are available here :http://www.robotc.net/forums/viewtopic.php?f=1&t=2753 or on my source forge project (follow link in signature)
Best regards.
Miki.

I was pretty certain that you cannot actually do this, but as Dick Swan said:
Dick Swan wrote:
"Data hiding" or "function hiding" in this case makes sense as is one of the elements of good programming practice.

I thought that I would ask and confirm since ROBOTC borrows some features from C++. I realize that he most likely meant using programming practice, not syntax.

_________________
sudo rm -rf /


Sun Feb 19, 2012 4:23 pm
Profile
Rookie

Joined: Thu Mar 13, 2014 6:12 am
Posts: 18
Post Re: How do you access methods #include files?
I was testing the '#include' command, before inserting it into my main program, when these error came up:

16.010 *Warning*:Substituting similar variable 'SensorType' for 'SENSORTYPE'. Check spelling and letter case.
2 **Error**:Duplicate definition for task 'main'.

I checked both programmes, and neither had errors, or code on line 16! Here are the programme codes:
Code:

#pragma systemFile

int hi;


void tst()
{

SENSORTYPE(S1) = sensorSONAR;

hi = SensorValue(S1);

motor(motorB) = hi;

}

task main()
{
}


Code:
#include "tstprt1.c"
task main()
{

tst();

}


Could any of you help me?


Tue Jul 08, 2014 7:41 am
Profile
Rookie

Joined: Thu Mar 13, 2014 6:12 am
Posts: 18
Post Re: How do you access methods #include files?
:D I figured out the problem. Because they were 'jointed', the errors from the first programme carried over to the other*.

(* I'm not sure what the proper term is)


Tue Jul 08, 2014 8:26 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 12 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.