| Author |
Message |
|
Ujomin
Rookie
Joined: Fri Feb 17, 2012 10:39 pm Posts: 3
|
 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: 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 |
|
 |
|
NeXT-Generation
Senior Roboticist
Joined: Wed Sep 28, 2011 10:13 pm Posts: 528 Location: Totally not spying on Hassenplug to see what he has for the Brickworld Chicago 2013 sumo contest.
|
 Re: How do you access methods #include files?
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 |
|
 |
|
magicode
Moderator
Joined: Tue Sep 14, 2010 9:19 pm Posts: 496
|
 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 |
|
 |
|
Ujomin
Rookie
Joined: Fri Feb 17, 2012 10:39 pm Posts: 3
|
 Re: How do you access methods #include files?
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 |
|
 |
|
Dick Swan
Creator
Joined: Fri Feb 09, 2007 9:21 am Posts: 613
|
 Re: How do you access methods #include files?
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 |
|
 |
|
Ujomin
Rookie
Joined: Fri Feb 17, 2012 10:39 pm Posts: 3
|
 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.
|
| Sat Feb 18, 2012 8:30 pm |
|
 |
|
Dick Swan
Creator
Joined: Fri Feb 09, 2007 9:21 am Posts: 613
|
 Re: How do you access methods #include files?
"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 |
|
 |
|
magicode
Moderator
Joined: Tue Sep 14, 2010 9:19 pm Posts: 496
|
 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 |
|
 |
|
mightor
Moderator
Joined: Wed Mar 05, 2008 8:14 am Posts: 2905 Location: Rotterdam, The Netherlands
|
 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
_________________| Some people, when confronted with a problem, think, "I know, I'll use threads," | and then two they hav erpoblesms. (@nedbat)| My Blog: I'd Rather Be Building Robots| ROBOTC 3rd Party Driver Suite: [ Project Page]
|
| Sun Feb 19, 2012 12:22 pm |
|
 |
|
magicode
Moderator
Joined: Tue Sep 14, 2010 9:19 pm Posts: 496
|
 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: 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 |
|
|