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:

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

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-generationSelf-proclaimed genius, and future world dominator.My Brickshelf Folder"Don't they teach recreational mathematics anymore?" - The Tenth DoctorBow 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 pmPosts: 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 pmPosts: 3

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 . 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

Dick Swan

Creator

Joined: Fri Feb 09, 2007 9:21 amPosts: 616

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

Ujomin

Rookie

Joined: Fri Feb 17, 2012 10:39 pmPosts: 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.

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.

Who is online

Users browsing this forum: No registered users and 2 guests

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