Hex constants?

New to FreeBASIC? Post your questions here.
KenHorse
Posts: 56
Joined: Jan 27, 2012 0:08

Hex constants?

Post by KenHorse »

How do I do this?

Code: Select all

Const Test = &H12
Doesn't seem to work
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Hex constants?

Post by fxm »

It works.

Code: Select all

Const Test = &H12
Print Hex(Test)
Flyzone
Posts: 109
Joined: Nov 17, 2017 17:39

Re: Hex constants?

Post by Flyzone »

As a side note, the "&" symbol seems to get lost in the documentation, only for you to find or discover it in "Literals". It seems it should show up in the Keyword or Operators list, or some other appropriate section, where it would be listed and then referenced to the Literals section.

I'm not sure if there are other symbols like this but, if so, they should be documented in a similar way.

My 2 cents.
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Hex constants?

Post by fxm »

'&h', '&b' and '&o' are not keywords or operators like '&' or '&=', but only prefixes for integer literals.
Perhaps the only thing we could at best consider is adding a link to this Literals page from the root page of the documentation (at the end of the section 'Language Documentation'/'Variables and Data Types'):

FreeBASIC Manual
Flyzone
Posts: 109
Joined: Nov 17, 2017 17:39

Re: Hex constants?

Post by Flyzone »

Yes, I understand the problem with the "not operators/keywords" taxonomy. It's no longer a problem for me but at one time I went crazy looking for how to do that hex "tool" thing with the &. The problem is, as a beginner, you have to already know what you are looking for to find it in "Literals". Since you already have a section on Literals, the change is appreciated but not really helpful, so less is more in that case.

My first notion was to go to the Alphabetical Index where there are other symbols like the "$" and others special characters to find it but for whatever reason, probably taxonomy, it is not there. I later stumbled on it in some example.

Since it is probably just me, I wouldn't worry about it. In reading the post it reminded me of the problem I had finding it, therefore my suggestion.

Thanks for the consideration.
srvaldez
Posts: 3373
Joined: Sep 25, 2005 21:54

Re: Hex constants?

Post by srvaldez »

I agree that having the suffixes in the index would be very helpful
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Hex constants?

Post by fxm »

Otherwise, in the 'Alphabetical Keyword List', perhaps adding a new extra section below the first extra section ('Operators'):
Alphabetical Keywords List
Operators
Prefixes and suffixes on Literals
.
_
#
.....
What is your opinion ?

Example of prefix + suffix applied on an integer literal ('12'):

Code: Select all

Var I = &h12ull
#print typeof(I)  '' ULONGINT
Print I           '' 18

Sleep
Flyzone
Posts: 109
Joined: Nov 17, 2017 17:39

Re: Hex constants?

Post by Flyzone »

Since you already have a section on Literals in Lexical Conventions, I don't really think this solves anything. The problem is one of finding it in an intuitive and alternative way. The Alpha index provides that alternate search path when one does not know that the & is a "Literal" but can find it anyway. This does not do that IMHO.
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Hex constants?

Post by fxm »

I do not see why we would particularize the prefixes '&h', '&b', and '&o', whereas this is not the case for all the very numerous symbolic operators (about thirty pure symbolic operators) which are not in the index list but only grouped in the extra section "Operators" (only named and non-combined operators are quoted individually in the index list).
Flyzone
Posts: 109
Joined: Nov 17, 2017 17:39

Re: Hex constants?

Post by Flyzone »

OK then, don't change anything if the solution doesn't solve the lookup problem. Maybe another solution will become apparent later.
Thanks.
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Hex constants?

Post by fxm »

Doing nothing, it is not my habit but I can resolve to do it !
Flyzone
Posts: 109
Joined: Nov 17, 2017 17:39

Re: Hex constants?

Post by Flyzone »

OK. If you have to do something, put only the & (not the specific prefixes like &h, &o, etc.) in the Alphabetic index pointing to Literals. If for consistency you have to add others it would likely be helpful to add them as well. I see a new problem with the multiple use of & in USING and elsewhere but that's a new problem for you :)

EDIT: Actually that is easily resolvable since you can add the multiple uses to the pointed list (like you do for PRINT, RETURN and others.)
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Hex constants?

Post by fxm »

But I cannot explicitly reference '&' as an index in the list without also quoting the string concatenation operator '&', and therefore make it a special case by explicitly quoting that operator only.
That is why I am so bothered !

Edit:
My reasoning fails because there is already the symbol '.' in the index list which only points to ellipsis ('...') and not also to the member access operator ('.').

So like this ?
Alphabetical Keywords List
Operators
&
.
_
#
.....
paul doe
Moderator
Posts: 1730
Joined: Jul 25, 2017 17:22
Location: Argentina

Re: Hex constants?

Post by paul doe »

fxm wrote: Jan 18, 2023 16:22 But I cannot explicitly reference '&' as an index in the list without also quoting the string concatenation operator '&', and therefore make it a special case by explicitly quoting that operator only.
That is why I am so bothered !
...
Disambiguation pages, like in Wikipedia? Where you have a page that points to all the uses of a symbol.
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Hex constants?

Post by fxm »

fxm wrote: Jan 18, 2023 16:22 But I cannot explicitly reference '&' as an index in the list without also quoting the string concatenation operator '&', and therefore make it a special case by explicitly quoting that operator only.
That is why I am so bothered !

Edit:
My reasoning fails because there is already the symbol '.' in the index list which only points to ellipsis ('...') and not also to the member access operator ('.').

Another solution (best in my opinion) would be to remove the extra 'Operators' section and add each missing operator (symbolic or combined) to the list:
Alphabetical Keywords List
+
!
  • ! (Escaped String Literal)

#
  • # (Argument stringize)
  • ## (Argument concatenation)

$
  • $ (Non-Escaped String Literal)

&
  • & (String concatenation with conversion)
  • &= (Concatenate and Assign)
  • &H, &B, &O (See Literals)

(
  • () (Array index)

[
  • [] (String index)
  • [] (Pointer index)

*
  • * (Multiply)
  • *= (Multiply and Assign)
  • * (Value of)

+
  • + (Add)
  • + (String concatenation)
  • += (Add and Assign)

-
  • - (Negate)
  • - (Subtract)
  • -= (Subtract and Assign)
  • -> (Pointer to member access)

.
  • . (Member access)

/
  • / (Divide)
  • /= (Divide and Assign)

\
  • \ (Integer divide)
  • \= (Integer Divide and Assign)

<
  • < (Less than)
  • <= (Less than or equal)
  • <> (Not equal)

=
  • =[>] (Assignment)
  • = (Equal)

>
  • > (Greater than)
  • >= (Greater than or equal)

@
  • @ (Address of)

^
  • ^ (Exponentiate)
  • ^= (Exponentiate and Assign)

A
  • AND=

E
  • EQV=

I
  • IMP=

L
  • LET (Assign)
  • LET() (Assignment)

M
  • MOD=

O
  • OR=

S
  • SHL=
  • SHR=

X
  • XOR=
Post Reply