CONST errors

Questions about the BASICtools and MakeItC
olzeke51
Posts: 317
Joined: Sat May 17, 2014 4:22 pm
Location: South Carolina
Contact:

Re: CONST errors

Post by olzeke51 » Tue Jan 23, 2018 10:33 pm

Thank you for that explanation of the two processes - C pre-processor and the BASIC compiler.
'
I was under the (initial) impression I could save RAM by using the CONST ... AS BYTE = {d1,d2,etc}
since the { d1,etc} is the assignment also !!
Later I see that CONST integers are kept in PC memory, but 'BYTE' and "$stings" are in RAM
'
to move on , I have DIM'd my arrays and manually assigned each element
'**********
CONST AS BYTE causes issues - the minute I made them INTEGER[default] all my <<<<<its on your list, again Thanks
issues went away - {GOSUBS/CALL using the array(index) as a passing parameter }

Code: Select all

		GOSUB dispSEGs(num2(0), num2(1), num2(2), num2(3), num2(4))
GOSUB dispSEGs(num0(0), num0(1), num0(2), num0(3), num0(4), num0(5))
-ERROR C:/Users/Zwanster/DOCUME~1/Coridium/prot0-dice.bas: 110: expected comma

* * * * * when USING 'AS BYTE'

GOSUB dispSEGs(num0(0), num0(1), num0(2), num0(3), num0(4), num0(5))
-ERROR C:/Users/Zwanster/DOCUME~1/Coridium/prot0-dice.bas: 110: Expected End Of Line



basicchip
Posts: 855
Joined: Fri Oct 19, 2012 2:39 am
Location: Lake Tahoe, CA
Contact:

Re: CONST errors

Post by basicchip » Tue Jan 23, 2018 10:47 pm

You are not giving me enough context. The definitions of num0(0) is probably the issue, but I can't tell why.
Single CONST are not stored anywhere, they are just replaced compile time.

Array CONST are stored in high Flash, just like constant strings.

What is a constant string?

DIM s(30) AS STRING

s = "this is a constant string"

While s is a variable string kept in RAM

PS GOSUB is not required for a defined SUB/FUNCTION

olzeke51
Posts: 317
Joined: Sat May 17, 2014 4:22 pm
Location: South Carolina
Contact:

Re: CONST errors

Post by olzeke51 » Tue Jan 23, 2018 10:59 pm

context:

Code: Select all

CONST num0 = {segA, segB, segC, segD, segE, segF}
CONST num1 = {segB, segC}
CONST num2 AS BYTE = {segA,segB,segG,segE,segD}   <<<< causes failures with the GOSUBS [ie.  'comma' , 'end of line']
'...
since I am calling a SUB with a PARAMARRAY, I used the (index)

Code: Select all

SUB dispNUM(anumber)

SELECT anumber

	CASE 0

		dispSEGs(num0(0), num0(1), num0(2), num0(3), num0(4), num0(5))

basicchip
Posts: 855
Joined: Fri Oct 19, 2012 2:39 am
Location: Lake Tahoe, CA
Contact:

Re: CONST errors

Post by basicchip » Tue Jan 23, 2018 11:15 pm

While I really don't want to see the whole program, you need to isolate what you think is wrong. I typically type these things directly into the Enter: line of BASIC to test

Code: Select all

const x as byte ={0x31,0x32,0x33,0x34}
print x
print hex(x(2))
works for me

Code: Select all

const x as byte ={0x31,0x32,0x33,0x34}
sub yy(z)
print hex(z)
endsub
main:
print x
yy(x(3))
Also works -- this is the kind of example I expect to see -- pointing at the line in error

olzeke51
Posts: 317
Joined: Sat May 17, 2014 4:22 pm
Location: South Carolina
Contact:

Re: CONST errors

Post by olzeke51 » Wed Jan 24, 2018 1:38 am

I was wondering if a BYTE value being put into an INTEGER position is the issue

here is a short program in its entirety

Code: Select all

#define segA  15	'SP35
#define segB  60	'SP27
#define segC  16	'SP12
CONST pinsSEG AS BYTE = {segA, segB, segC}
'
SUB dispSEG(PARAMARRAY z)
	PRINT z(0),
	PRINT z(1),
	PRINT z(2)
ENDSUB
'
Main:
dispSEG(pinsSEG(0),pinsSEG(1),pinsSEG(2))
STOP
END
here is compiler message:
ARMbasic[9.37m] on the PC Copyright 2017, Coridium Corp.

dispSEG(pinsSEG(0),pinsSEG(1),pinsSEG(2))
-ERROR C:/Users/Zwanster/Coridium/const_.BAS: 14: expected comma

dispSEG(pinsSEG(0),pinsSEG(1),pinsSEG(2))
-ERROR C:/Users/Zwanster/Coridium/const_.BAS: 14: Expected End Of Line

dispSEG(pinsSEG(0),pinsSEG(1),pinsSEG(2))
-First ERROR at line :14
'
If I remove the AS BYTE I get this
Commercial customers contact Coridium for licensing

15 60 16

Coridium Break:

basicchip
Posts: 855
Joined: Fri Oct 19, 2012 2:39 am
Location: Lake Tahoe, CA
Contact:

Re: CONST errors

Post by basicchip » Wed Jan 24, 2018 2:00 am

So AS BYTE is confusing PARAMARRAY

add it to the list, as long as there are reasonable workarounds, it goes into the queue. Start of BASIC.c ---

Code: Select all

// to do-
// bugs
//
//	const a=1
//	const x={a...}	' a is not recognized as a constant values
//
//	const x AS BYTE = {...}
//	...
//	sub asub (PARAMARRAY z)
//	..
//	asub (x(0), x(1)...)	' not compiling, should just be converted to integer values

olzeke51
Posts: 317
Joined: Sat May 17, 2014 4:22 pm
Location: South Carolina
Contact:

Re: CONST errors

Post by olzeke51 » Sat Mar 10, 2018 10:32 pm

FYI only: the CONST statement can't handle a dash "-" in the name of the array.
Will need to use the underscore [which is harder to type IMO]
Duhhh - that is a minus sign!!

throws this type of error message:
CONST SPINS-longname = {2, 52, 21, 56, 7, 63, 8, 22,
-ERROR C:/Users/Zwanster/Documents/Coridium/BASIClib/STAMP_PINS_long.bas: 112: Expected =

61, 12, 45, 54, 16, 23, 17, 57,
-ERROR C:/Users/Zwanster/Documents/Coridium/BASIClib/STAMP_PINS_long.bas: 113: Expected lvalue: variable, pointer, or register

basicchip
Posts: 855
Joined: Fri Oct 19, 2012 2:39 am
Location: Lake Tahoe, CA
Contact:

Re: CONST errors

Post by basicchip » Sat Mar 10, 2018 10:37 pm

CONST names follow the same syntax as variable names.

In BASIC that means starting with letter or _ followed by letters, numbers or _

Few compilers if any I know of allow - (minus sign as a name). How would you ever know if it is a name or name - minus another_name.

Vermillion
Posts: 1
Joined: Tue Mar 27, 2018 9:19 am

Re: CONST errors

Post by Vermillion » Sat Apr 07, 2018 6:53 am

I agree, that's pretty confusing. Are developers usually aware of this issue?

Post Reply