View previous topic :: View next topic |
Author |
Message |
georgecharlton
Joined: 01 Jul 2011 Posts: 3 Location: Palmerston North
|
Posted: Tue Feb 03, 2015 9:05 am Post subject: Bascom does not recognise "BYREF" when declaring a |
|
|
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 |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Tue Feb 03, 2015 9:44 am Post subject: |
|
|
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 |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Tue Feb 03, 2015 10:02 am Post subject: Re: Bascom does not recognise "BYREF" when declari |
|
|
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 |
|
|
georgecharlton
Joined: 01 Jul 2011 Posts: 3 Location: Palmerston North
|
Posted: Wed Feb 04, 2015 10:31 am Post subject: |
|
|
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 |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Wed Feb 04, 2015 3:45 pm Post subject: |
|
|
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 |
|
|
georgecharlton
Joined: 01 Jul 2011 Posts: 3 Location: Palmerston North
|
Posted: Sat Feb 07, 2015 10:57 pm Post subject: Bascom does not recognise BYREF |
|
|
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 |
|
|
|