[Gambas-user] Constant expressions

Fabien Bodard gambas.fr at gmail.com
Wed Oct 13 10:32:01 CEST 2021


Found it !!! BugTraker Request #775 :-D

Le mer. 13 oct. 2021 à 10:11, Fabien Bodard <gambas.fr at gmail.com> a écrit :

> Enfin !!!
>
> mdr 4 month you say 😂... well hum... If I remember well I've querying
> that during my first attempt on the gb.form.terminal.
>
> So ... Thank you a lot !!!
>
> Le mer. 13 oct. 2021 à 00:32, Brian G <brian at westwoodsvcs.com> a écrit :
>
>> This is amazing! Thank you so much!
>>
>> "Failure is the key to success;
>>  each mistake teaches us something"  .. Morihei Ueshiba
>> Brian G
>>
>> ----- On Oct 12, 2021, at 6:00 AM, Benoît Minisini g4mba5 at gmail.com
>> wrote:
>>
>> > Hi,
>> >
>> > I have implemented in the compiler the ability to use "constant
>> > expressions".
>> >
>> > Constant expressions are integer expressions that are evaluated at
>> > compile time, and that can be used in the following places:
>> >
>> > - Constant declarations.
>> >
>> > - Enumeration declarations.
>> >
>> > - Embedded array declarations.
>> >
>> > These expressions only support a subset of Gambas operators and
>> > pre-defined constants.
>> >
>> > Here is the list of what you can use inside a constant expression:
>> >
>> > - Arithmetic operators: +, -, *, /, \, Div, %, Mod
>> >
>> > - Logical operators: And, Or, Xor, Not
>> >
>> > - Bitwise operators: Shl, Shr, Asl, Asr, Lsl, Lsr
>> >
>> > - Size of a native numerical or date datatype: SizeOf()
>> >
>> > - Native datatype constants : gb.Boolean, gb.Byte, gb.Short, gb.Integer,
>> >   gb.Long, gb.Single, gb.Float, gb.Date.
>> >
>> > - Another integer constant.
>> >
>> > WARNING! In the context of constant integer expressions, The / operator
>> > acts like the integer division operator \.
>> >
>> > Note that the bitwise operators now can used like... operators, and must
>> > be used that way in the context of constant integer expressions
>> >
>> > Here are some examples:
>> >
>> >   Public Const Alpha As Integer = 1
>> >   Public Const Beta As Integer = (Alpha * 2) + 1
>> >   Public Const Delta As Byte = Beta + Alpha
>> >
>> >   Private Enum FirstFlag = 1 Shl 0, SecondFlag = 1 Shl 1,
>> >     ThirdFlag = 1 Shl 2
>> >
>> >   Private SomeEmbeddedArray[Delta * SizeOf(gb.Short)] As String
>> >
>> > The corresponding documentation is available in the wiki here:
>> >
>> > https://gambaswiki.org/edit/lang/constexpr
>> >
>> > Enjoy it!
>> >
>> > --
>> > Benoît Minisini
>> >
>> > ----[ http://gambaswiki.org/wiki/doc/netiquette ]----
>>
>> ----[ http://gambaswiki.org/wiki/doc/netiquette ]----
>>
>
>
> --
> Fabien Bodard
>


-- 
Fabien Bodard
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20211013/89e09d54/attachment.htm>


More information about the User mailing list