#include

techElder

Well-known member
The literature says nothing about the location of the directive #INCLUDE filename.basinc within a source file.

Does it matter where it is located?
 

eggdweather

Senior Member
Does it work? The Manual says:
#include “filename”
Include code from a separately saved file within this program.
Example: #include “c:\test.bas”
NOTE: Reserved for future use. Not currently implemented.

So that last statement suggests there are issues, but if it did work, I'd expect to 'include' it where I wanted the code to be inserted in the main code.
 

Circuit

Senior Member
NOTE: Reserved for future use. Not currently implemented.

So that last statement suggests there are issues, but if it did work, I'd expect to 'include' it where I wanted the code to be inserted in the main code.
The manual is not as up-to-date as the on-line reference. Click on "BASIC Commands" at the top of this forum; select Directives and lookup #include. No mention of it not being currently implemented.
 

tarzan

Senior Member
pe6.pdf

page 21

As the compiler processes ’top-to-bottom’ on the pre-processor output file it is necessary to take care to ‘skip’ the #INCLUDE file (if necessary) when it is included at the top of a program.
 

techElder

Well-known member
Thanks, Technical. This is the kind of thing that is missed over and over in the manuals. I hope it gets better.

#include will insert text at that exact point

PS. The other answers missed the question completely. You actually have to read what people write. Nice try.
 

tarzan

Senior Member
PS. The other answers missed the question completely. You actually have to read what people write. Nice try.
You said
The literature says nothing about the location of the directive #INCLUDE filename.basinc within a source file.
The literature does say something about its location in pe6.pdf page 21.

You ask
Does it matter where it is located?
The quote from pe6.pdf gives one example where it may matter.

You can lead a horse to water, but you can't make it drink.
 

srnet

Senior Member
The literature does say something about its location in pe6.pdf page 21.
The quote from pe6.pdf gives one example where it may matter.
And worth noting that if the include file is in the 'wrong' place you will get an error.
 

techElder

Well-known member
This is not saying where the #include file should be located ... so more is needed.

... As the compiler processes ’top-to-bottom’ on the pre-processor output file it is necessary to take care to ‘skip’ the #INCLUDE file (if necessary) when it is included at the top of a program.
Reset_here: Goto Init #INCLUDE “sphero.basinc” Init:
; jump over include file
; start program here
 

techElder

Well-known member
Thus the reason for my question. I didn't get an error. My program just didn't work as expected.

And worth noting that if the include file is in the 'wrong' place you will get an error.
Actually, you can't always lead a horse to water, and you can make them drink if you can lead them there. I know.
 

hippy

Technical Support
Staff member
A #INCLUDE directive can be placed anywhere you want, however you may need to consider the consequences of where it is placed.

If the #INCLUDE file includes a SYMBOL definition used by your program the #INCLUDE has to be before that symbol is used or it won't have been defined when it is used, will generate an error.

Likewise though, if the #INCLUDE file includes an END statement and you include it before your main program then that will get executed unless you take care not to execute it and execution will never reach your own program.

Using #INCLUDE is effectively doing a copy-and-paste of the text in the #INCLUDE file to where the #INCLUDE directive appears.
 
Top