View previous topic :: View next topic |
Author |
Message |
njepsen
Joined: 13 Aug 2007 Posts: 469
|
Posted: Fri Sep 13, 2019 8:38 am Post subject: Problem Understanding CONFIG SUBMODE = NEW |
|
|
Historically. I have been using submode = old, and I am reluctant to change because my program is 8000 lines long, with many units in the field.
But I am considering it.
I have a question- the help for submode says Quote: |
When working with $include files, this requires that you insert an $include file with the SUBS/FUNCTIONS at the end of your code, and that you insert an $include file with the DECLARE statements at the start of your code. |
Does this mean that when using submode = old, there needs to be TWO iterations of $include? One at the end of the code and one with the declarations?
This is confusing because the help for $include says
Quote: | An include file will only be included once, even if you include it multiple times.
|
(BASCOM-AVR version : 2.0.7.9 , Latest : 2.0.8.2 ) _________________ Neil |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5914 Location: Holland
|
Posted: Fri Sep 13, 2019 9:04 am Post subject: |
|
|
it means what it says.
But there are 2 different include files. Like this :
$regfile...
$include "myheaders.inc"
your code
$include "mysubs.inc"
myheaders.inc would have content like :
declare sub test()
and mysubs.inc would have the implementation like:
sub test()
..
end sub
When using submode=new, there is no need for a declaration as they are extracted from the implementation. And you must put the implementation before the main code since otherwise the calling code has no idea about these subs and functions.
In that case the code will end up after your code and only the used modules are included. in the old way, the code ends up where you put it.
For that case it is needed that the implementation goes behind the code. and since the calling code has no idea in that case, you must put the declaration in front.
Otherwise consider this :
your code
...
sub test
nop
end sub
the main code would walk into the sub and get a return without calling.
submode=new will remove that code and put it automatic behind your code and only the modules that were actually used. _________________ Mark |
|
Back to top |
|
|
njepsen
Joined: 13 Aug 2007 Posts: 469
|
Posted: Fri Sep 13, 2019 9:57 pm Post subject: |
|
|
Thankyou mark for taking the time to explain that.
You said:
Quote: | Otherwise consider this :
your code
...
sub test
nop
end sub
the main code would walk into the sub and get a return without calling. |
and I dont understand this in the context that my code ( which I assume is what most people do) is this:
Code: |
declarations etc
do
my code
call subs & functions
loop
sub()
end sub
sub()
end sub
function
end function
etc
end | [/code] _________________ Neil |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5914 Location: Holland
|
Posted: Tue Sep 17, 2019 10:04 am Post subject: |
|
|
you show no include. please read your original questions and my reply.
i have no idea about what you find confusing but when you do not use include as in your sample, you can ignore it.
if you do use include, show an actual good short sample. _________________ Mark |
|
Back to top |
|
|
njepsen
Joined: 13 Aug 2007 Posts: 469
|
Posted: Tue Sep 17, 2019 10:01 pm Post subject: |
|
|
Hi Mark,
I understand your explanation about Include.
What i was commenting on was your statement about code "walking into the subs", and was asking - why would you write code that simply wandered on aimlessly into a sub; why not use a loop to prevent this, as i showed. _________________ Neil |
|
Back to top |
|
|
MichaelB.
Joined: 04 May 2017 Posts: 58
|
Posted: Thu Oct 03, 2019 8:36 pm Post subject: |
|
|
Hello,
My first confrontation with with a .inc File.
I used vers. 2.0.8.1:
Edit: Same Problem in vers. 2.0.8.2
$lib "glcdKS108.lib"
Config Submode = New
$Include "Test.inc"
// the Test.inc is used to Draw a Box and make other calculations. The "Calculations" dont have any effect for the Box drawing. It is the Same Box Draw as the Regular Bascom Statement, but i want to have it in the SUB, to have it all in one.
Do
Draw_Box 10 , 10 , 0 , 0 , 1
Loop
End
// But it do not execute it well, it draws a Box out of Dimensions. Sometimes a Stripe on the Egde.
// When i Extract the Box drawing Bascom Statement from the .inc File Box (10 , 10) - (0 , 0), 1
// to the DO Loop, it works as expected, but the rest in the .inc File isnt Working. |
|
Back to top |
|
|
AdrianJ
Joined: 16 Jan 2006 Posts: 2483 Location: Queensland
|
Posted: Sat Oct 05, 2019 12:28 am Post subject: |
|
|
@njepsen
Maybe just to clarify a bit further:
If you dont use $includes at all, then its up to you to ensure your declarations, main code and subs are in the right places. You seem to do this already. In that case it wont matter whether you use submode = new or not.
Many people however want to keep all their commonly used subs in include files, and just $include the lot, or whichever ones they use for a given project. Then with submode = old, it matters that there have to be separate inc files for the declarations and the actual sub codes, and the programmer has to put the $includes in the right places in the main code.
For people who do this, it makes it very much easier for them if the declarations and the sub codes are all together in one include file, and let the compiler figure out where to put all the bits. So they use submode = new. _________________ Adrian Jansen
Computer language is a framework for creativity |
|
Back to top |
|
|
njepsen
Joined: 13 Aug 2007 Posts: 469
|
Posted: Sat Oct 05, 2019 12:50 am Post subject: |
|
|
That clarifies it nicely. Thanks Adrian.
neil _________________ Neil |
|
Back to top |
|
|
|