Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Problem Understanding CONFIG SUBMODE = NEW

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
njepsen

Bascom Member



Joined: 13 Aug 2007
Posts: 392

newzealand.gif
PostPosted: Fri Sep 13, 2019 8:38 am    Post subject: Problem Understanding CONFIG SUBMODE = NEW Reply with quote

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
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 4797
Location: Holland

blank.gif
PostPosted: Fri Sep 13, 2019 9:04 am    Post subject: Reply with quote

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
View user's profile Visit poster's website
njepsen

Bascom Member



Joined: 13 Aug 2007
Posts: 392

newzealand.gif
PostPosted: Fri Sep 13, 2019 9:57 pm    Post subject: Reply with quote

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
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 4797
Location: Holland

blank.gif
PostPosted: Tue Sep 17, 2019 10:04 am    Post subject: Reply with quote

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
View user's profile Visit poster's website
njepsen

Bascom Member



Joined: 13 Aug 2007
Posts: 392

newzealand.gif
PostPosted: Tue Sep 17, 2019 10:01 pm    Post subject: Reply with quote

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
View user's profile
MichaelB.

Bascom Member



Joined: 04 May 2017
Posts: 39

germany.gif
PostPosted: Thu Oct 03, 2019 8:36 pm    Post subject: Reply with quote

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
View user's profile
AdrianJ

Bascom Expert



Joined: 16 Jan 2006
Posts: 2457
Location: Queensland

australia.gif
PostPosted: Sat Oct 05, 2019 12:28 am    Post subject: Reply with quote

@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
View user's profile Visit poster's website
njepsen

Bascom Member



Joined: 13 Aug 2007
Posts: 392

newzealand.gif
PostPosted: Sat Oct 05, 2019 12:50 am    Post subject: Reply with quote

That clarifies it nicely. Thanks Adrian.

neil

_________________
Neil
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum