How does #include really work?

I would like to have a competition code that uses autons, robot functions, and driver control codes that are in different files. This will help keep the code organized and will be easier to navigate. Is that possible? And do I just put #inlcude [file name or path].[file type]? Thank you in advance.

Yup.

Yes including files is a great way to organize your code - especially if you have different programs for skills.

The include does exactly what you think, replace that line with the file. It includes the contents of the entire file in the flow of code to compile. So think of it inserting a file right there and as you go top down in compiling away.

The #include reads through the path of directories set by an environment variable. The current directory is generally the first thing in the path to look for files. I can’t remember which variable that is is it PATH or does Robot C have an include path variable it wants to use? Either way, current directory is generally a good place to put files and I am not sure you will have too too many of them.

But include files are great ways to have your PID or other functions used year over year.

How would I control when it begins? Like for an auton, can I give commands for it to start inside the autonomous part of the competition code? Does a code automatically start where its #include is in another code?

I guess I shouldn’t have given such a short answer. Team Giraffes (as usual) has a great summary of the advantages of using #include. We have found that it really minimizes inadvertent programming errors (going in to fix one thing but accidentally breaking something else). By using "#include, you can compartmentalize your code.

As to your latest question, the #include for us normally has either tasks or voids. Within the code you can start the task or invoke the void and it will run. The code in the #include will not run by itself unless you call it.

Ok then, thank you for all the info!

wait… If i ran a #include could i fit more sound files into the program?

It doesn’t work that way.


#include

only means something to the compiler; it doesn’t get compiled into machine code to run on the Cortex.

Memory limits will be the same either way.

I’m trying to use #inlcude but it isn’t working. I think I’m using the wrong syntax. Does anybody know the correct syntax? Here’s the error I keep getting:

*Severe:Couldn’t open ‘#include’ file ‘robotFunctionList.c’

You have to have included files in the directories you specify in the RobotC settings.

or just put all the source files in the same folder.