Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Bascom does not recognise "BYREF" when declaring a

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

Bascom Member



Joined: 01 Jul 2011
Posts: 3
Location: Palmerston North

newzealand.gif
PostPosted: Tue Feb 03, 2015 9:05 am    Post subject: Bascom does not recognise "BYREF" when declaring a Reply with quote

Hi,
I am running Bascom ver. 2.0.7.7 and when I enter a subroutine declaration
eg. DECLARE SUB MYSUB (byref a as byte, BYVAL b as byte)
the compiler/editor does not recognise the word “byref” ( it should change the lettering blue, same as BYVAL

When I attempt to compile it, the error message:

Error: 248 Line: 123 BYVAL should be used in declaration [[112]], in File: C:\dir\file.bas

If I leave “byref” out, it should default to BYREF according to the Declare explanation, but I get the same error message.

any help gratefully accepted.

George C
N.Z.

(BASCOM-AVR version : 2.0.7.7 , Latest : 2.0.7.8 )
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 4966
Location: Holland

blank.gif
PostPosted: Tue Feb 03, 2015 9:44 am    Post subject: Reply with quote

yes I see there is no coloring, will add that.
you should post some small but complete code. i guess what you do is passing a number to a variable declared with byref.

_________________
Mark
Back to top
View user's profile Visit poster's website
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 1801

blank.gif
PostPosted: Tue Feb 03, 2015 10:02 am    Post subject: Re: Bascom does not recognise "BYREF" when declari Reply with quote

georgecharlton wrote:
the compiler/editor does not recognise the word “byref” ( it should change the lettering blue, same as BYVAL

ByRef gets recognized, and the missing highlight is old news.
Quote:
If I leave “byref” out, it should default to BYREF according to the Declare explanation, but I get the same error message.

Because you call the sub with parameter a as constant, then the call "by reference" is not possible.
ByRef means the address of the original variable is forwarded, if you use a constant, there is no address to forward.
Thus ByVal is required, which creates a temporary variable, where the constant is assigned to.
Back to top
View user's profile
georgecharlton

Bascom Member



Joined: 01 Jul 2011
Posts: 3
Location: Palmerston North

newzealand.gif
PostPosted: Wed Feb 04, 2015 10:31 am    Post subject: Reply with quote

Hi,

I was using a previously dim'd variable, now it is all working OK without the BYREF.

Thanks for the prompt answers.

George C
Back to top
View user's profile
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 1801

blank.gif
PostPosted: Wed Feb 04, 2015 3:45 pm    Post subject: Reply with quote

georgecharlton wrote:
I was using a previously dim'd variable

Then it would have worked.

As you ignored the wish to provide compilable code, so I did in this case:
Code:
$Regfile = "m328def.dat"
$crystal = 16000000
$hwstack = 40
$swstack = 16
$framesize = 32
$baud = 57600

Dim gvar As Byte

DECLARE SUB MYSUB(byref a as byte , BYVAL b as byte)

Do
   MYSUB gvar , 1
Loop

SUB MYSUB(byref a as byte , BYVAL b as byte)
   Print a ; " " ; b
End Sub

End

This code compiles without problems in 2.0.7.8, which would be not the case, if ByRef
Quote:
now it is all working OK without the BYREF.

would have been the culprit.

The culprit was, as so often, sitting in front of the screen.
Back to top
View user's profile
georgecharlton

Bascom Member



Joined: 01 Jul 2011
Posts: 3
Location: Palmerston North

newzealand.gif
PostPosted: Sat Feb 07, 2015 10:57 pm    Post subject: Bascom does not recognise BYREF Reply with quote

albertsm & MWS,

I had corrected the fault and overwritten the problem.
When I tried to re-create the code, I couldn't duplicate the original problem.
However . . .
It has just re-occured in my latest program and was, as you pointed out, due to the sub variable being passed as a constant in the calling line.
By assigning the constant to a variable & using the variable in the sub calling line the compiler is happy.

eg.

declare sub mysub(byref v1 as byte)

mysub $55 '<error!

Compiler flags error, but

x=$55
mysub x '< OK

=compiler happy

Thanks for your assistance
George
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