ROBOTC.net forums
http://www.robotc.net/forums/

How do you access methods #include files?
http://www.robotc.net/forums/viewtopic.php?f=11&t=4263
Page 1 of 1

Author:  Ujomin [ Fri Feb 17, 2012 10:45 pm ]
Post subject:  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

Author:  NeXT-Generation [ Fri Feb 17, 2012 11:50 pm ]
Post subject:  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.

Author:  magicode [ Sat Feb 18, 2012 2:50 am ]
Post subject:  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.

Author:  Ujomin [ Sat Feb 18, 2012 8:19 am ]
Post subject:  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!

Author:  Dick Swan [ Sat Feb 18, 2012 10:23 am ]
Post subject:  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.

Author:  Ujomin [ Sat Feb 18, 2012 8:30 pm ]
Post subject:  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.

Author:  Dick Swan [ Sun Feb 19, 2012 5:50 am ]
Post subject:  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.

Author:  magicode [ Sun Feb 19, 2012 11:23 am ]
Post subject:  Re: How do you access methods #include files?

Is it actually possible to do "encapsulation" in ROBOTC?

Author:  mightor [ Sun Feb 19, 2012 12:22 pm ]
Post subject:  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

Author:  magicode [ Sun Feb 19, 2012 4:23 pm ]
Post subject:  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.

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/