Define constant as a char

42 views
Skip to first unread message

Oliver Seitz

unread,
Jan 13, 2021, 3:21:07 AM1/13/21
to Jallib
Hi!

I can assign a char as an ascii-value to a variable.

I can't assign it to a constant:

const FORMAT_DECIMAL = "."

Compiler says error: type mismatch

I can assign it as a constant array:

const FORMAT_DECIMAL[] = "."

Would it be possible to allow the direct assignment to a single constant?

Greets,
Kiste

Mike

unread,
Jan 13, 2021, 6:10:55 PM1/13/21
to jallib
Hi Kiste,

Don't you need a variable type?

const byte FORMAT_DECIMAL = "."

Regards,
Mike

Oliver Seitz

unread,
Jan 14, 2021, 2:55:13 PM1/14/21
to 'Mike' via jallib
Hi Mike,

thanks for your reply. It is a constant, there can be a type, but there's no need. If no type is given, it becomes a "universal" type, which adjusts its size to the size of the variables it is used with.

But, still, if I try

const byte FORMAT_DECIMAL = "."

I get the same error.

For the time being, the workaround

const byte FORMAT_DECIMAL[] = "."

(with or without "byte") does the trick, the constant can be used without index, but the definition looks rather strange.


Greets,

Kiste

Am Donnerstag, 14. Januar 2021, 00:10:57 MEZ hat 'Mike' via jallib <jal...@googlegroups.com> Folgendes geschrieben:
--
You received this message because you are subscribed to the Google Groups "jallib" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jallib+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jallib/4149dfec-1cd9-41cf-ab5c-783539636f85n%40googlegroups.com.

Mike

unread,
Jan 15, 2021, 9:34:52 AM1/15/21
to jallib
Hi Kiste,

It looks like a bug that was introduced at some point.  I found an old JAL program, that I know compiled and worked fine, that has this line:

const TAG_UTC      = "a"

Perhaps it happened when going to JALv2, as my program has the old style of JAL code, like "include 16f88_4".

Regards,
Mike

Rob CJ

unread,
Jan 15, 2021, 1:02:42 PM1/15/21
to jal...@googlegroups.com
Hi Kiste,

I think Kyle must have had a reason for it to use the construction with [] also for single characters so I am not sure if we should fix this.

Kind regards,

Rob


Van: 'Mike' via jallib <jal...@googlegroups.com>
Verzonden: vrijdag 15 januari 2021 15:34
Aan: jallib <jal...@googlegroups.com>
Onderwerp: Re: [jallib] Re: Define constant as a char
 

Oliver Seitz

unread,
Jan 15, 2021, 1:35:21 PM1/15/21
to jal...@googlegroups.com
Hi Rob,

you're right, I don't know if it's a bug or a feature - that's the reason why I'm asking ;-)
Might be that there's a reason. At least, it is not documented.
jalv2.pdf shows examples of unnamed constants:

Numeric constants have the following formats:
12 --decimal
[...]
"a" --ASCII

There is no hint that for defining a named constant, only one type of the listed unnamed constant examples can't be used.
If it's on purpose, it should go into the docs, I think.

Greets,
Kiste


Am Freitag, 15. Januar 2021, 19:02:44 MEZ hat Rob CJ <rob...@hotmail.com> Folgendes geschrieben:
To view this discussion on the web visit https://groups.google.com/d/msgid/jallib/AM0PR07MB6241724C1357EF3F69966B6BE6A70%40AM0PR07MB6241.eurprd07.prod.outlook.com.

Oliver Seitz

unread,
Jan 15, 2021, 3:04:18 PM1/15/21
to jal...@googlegroups.com
Hi Rob,

it is no construction with [].

While I can define

const letter[]="A"

and I can send it to a pseudo-variable

serial_hw_data=letter

I can't compare or assign it to a variable:

if letter<55 then
  var byte another=letter
end if

gives "invalid operation"
So, the [] is no real workaround. The workaround now is to have a printed ascii table to look up by hand.

Greets,
Kiste

Am Freitag, 15. Januar 2021, 19:02:44 MEZ hat Rob CJ <rob...@hotmail.com> Folgendes geschrieben:







To view this discussion on the web visit https://groups.google.com/d/msgid/jallib/AM0PR07MB6241724C1357EF3F69966B6BE6A70%40AM0PR07MB6241.eurprd07.prod.outlook.com.

Matt Schinkel

unread,
Jan 15, 2021, 3:21:28 PM1/15/21
to jal...@googlegroups.com
const letter[]="A" is an array

Try:
if letter<55 then
  var byte another=letter[0]
end if


From: 'Oliver Seitz' via jallib <jal...@googlegroups.com>
Sent: January 15, 2021 3:04 PM
To: jal...@googlegroups.com <jal...@googlegroups.com>
Subject: Re: [jallib] Re: Define constant as a char
 

Oliver Seitz

unread,
Jan 15, 2021, 3:45:13 PM1/15/21
to jal...@googlegroups.com
Hi Matt,

that might work... but I don't want it to be an array... I just want it to be a constant of value 65 without looking it up by hand. It works when using a variable, it's documented to be valid, but it doesn't work.

I could use a variable. If a variable is only defined once and only read through the rest or the program, the compiler would replace it to be a constant. Using a variable, hoping the compiler will make a constant from it doesn't seem a good way to write a library.

The plan was to have a constant, which holds the char to use, or zero if the feature should be turned off.

These would look nice:
const FORMAT_THOUSANDS=0
const FORMAT_THOUSANDS=","

One would have to do it like
const FORMAT_THOUSANDS[]={0}
const FORMAT_THOUSANDS[]=","
and then, have a useless index [0] throughout the whole program. It doesn't look that good.

Ok, if all of you think it shouldn't work, I'll put the most usual chars in the comments, and users will have to read the sources to find out how to define things...

Greets,
Kiste



If I use it








Am Freitag, 15. Januar 2021, 21:21:30 MEZ hat Matt Schinkel <mattsc...@hotmail.com> Folgendes geschrieben:
To view this discussion on the web visit https://groups.google.com/d/msgid/jallib/YQXPR01MB414951F289FC979E3E77A325DEA70%40YQXPR01MB4149.CANPRD01.PROD.OUTLOOK.COM.

Matt Schinkel

unread,
Jan 15, 2021, 3:48:09 PM1/15/21
to jal...@googlegroups.com
I do agree with you, it should work. I was just pointing out a work around.

Matt.


From: 'Oliver Seitz' via jallib <jal...@googlegroups.com>
Sent: January 15, 2021 3:45 PM

Oliver Seitz

unread,
Jan 15, 2021, 3:53:27 PM1/15/21
to jal...@googlegroups.com
Ok then, thanks for the hint ;-)

Greets,
Kiste




Am Freitag, 15. Januar 2021, 21:48:10 MEZ hat Matt Schinkel <mattsc...@hotmail.com> Folgendes geschrieben:
To view this discussion on the web visit https://groups.google.com/d/msgid/jallib/YQXPR01MB4149C9E3FC942FD983B12BFBDEA70%40YQXPR01MB4149.CANPRD01.PROD.OUTLOOK.COM.

Oliver Seitz

unread,
Jan 16, 2021, 4:30:55 AM1/16/21
to 'Oliver Seitz' via jallib
I've found a workaround. Make it a calculation. This looks acceptable for now:

const FORMAT_THOUSANDS=0
or
const FORMAT_THOUSANDS=0+","

Greets and thanks to all :-)

Kiste

rob...@hotmail.com

unread,
Apr 5, 2021, 6:33:59 AM4/5/21
to jallib
Hi Kiste,

I think I fixed this issue. I have sent you a new - test - version jalv25r5 to your e-mail address.  Please give it a try.

Thanks

Kind regards,

Rob


Op zaterdag 16 januari 2021 om 10:30:55 UTC+1 schreef Kiste:
Reply all
Reply to author
Forward
0 new messages