Uinteger<32>

General FreeBASIC programming questions.
Post Reply
deltarho[1859]
Posts: 4317
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Uinteger<32>

Post by deltarho[1859] »

I saw Uinteger<32> here. Some of you may say: "How come you didn't know that?". Well, I didn't, and I cannot find it described in FBWiki. A Google search of the forum only found a few instances of Uinteger<32>; notably by MrSwiss.

It seems that Uinteger<32> = 32-bit unsigned integer in 32-bit mode or 64-bit mode = Ulong

By the same token:

Uinteger<64> = 64-bit unsigned integer in 32-bit mode or 64-bit mode = Ulongint
Integer<32> = 32-bit signed integer in 32-bit mode or 64-bit mode = Long
Integer<64> = 64-bit signed integer in 32-bit mode or 64-bit mode = Longint

All tested.

To my mind this begs the question of why do we have Ulong, Ulongint, Long, and Longint.

When I came to FreeBASIC I had no idea what Ulong was - I was using Dword. It is obvious to anyone migrating to FreeBASIC what Uinteger<32> is.

We could use:

#define Uint32 = Uinteger<32>
#define Uint64 = Uinteger<64>
#define Sint32 = Integer<32>
#define Sint64 = Integer<64>

I have a mind to use them in future.

Of course, we still have Uinteger and Integer as mode implicit.

For those we could use:

#define Uint3264 = Uinteger
#define Sint3264 = Integer

I have a mind to use them as well.
fxm
Moderator
Posts: 12186
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Uinteger<32>

Post by fxm »

deltarho[1859] wrote: Feb 14, 2022 3:28 I saw Uinteger<32> here. Some of you may say: "How come you didn't know that?". Well, I didn't, and I cannot find it described in FBWiki.
Simply on pages: INTEGER and UINTEGER
deltarho[1859]
Posts: 4317
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: Uinteger<32>

Post by deltarho[1859] »

Thanks, fxm.

Searching FBWiki is a nightmare. Uinteger<32> finds 96 matches. The first match comes up with 'Phrase not found'. So, why tell me there was a match?

Fell at the second hurdle. The first hurdle was not using libraries. :)

So we would have to use:
#ifndef Uint32
#define Uint32 = Uinteger<32>
#endif

for example. Image

Using your links we could create a more comprehensive bi, say IntDataTypes.bi to cover the 8 and 16 bit variants as well.
deltarho[1859]
Posts: 4317
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: Uinteger<32>

Post by deltarho[1859] »

I found Sint32 in some libraries, so came up with this:

IntDataTypes.bi

Code: Select all

#ifndef Uint8
  #define Uint8 = Uinteger<8>
#endif
#ifndef Uint16
  #define Uint16 = Uinteger<16>
#endif
#ifndef Uint32
  #define Uint32 = Uinteger<32>
#endif
#ifndef Uint64
  #define Uint64 = Uinteger<64>
#endif
#define Uint3264 = Uinteger
#ifndef Sint8
  #define Sint8 = Integer<8>
#endif
#ifndef Sint16
  #define Sint16 = Integer<16>
#endif
#ifndef Sint32
  #define Sint32 = Integer<32>
#endif
#ifndef Sint64
  #define Sint64 = Integer<64>
#endif
#define Sint3264 = Integer
It won't catch on? Ask a newcomer which they prefer? Uint64 or Ulongint.
Last edited by deltarho[1859] on Feb 14, 2022 8:28, edited 1 time in total.
adeyblue
Posts: 303
Joined: Nov 07, 2019 20:08

Re: Uinteger<32>

Post by adeyblue »

deltarho[1859] wrote: Feb 14, 2022 7:02 Using your links we could create a more comprehensive bi, say IntDataTypes.bi to cover the 8 and 16 bit variants as well.
Look in
inc/crt/stdint.bi
it defined them for every size

Also look in
inc/win/basetsd.bi (it's included by windows.bi, you don't have to remember the name)
for non _t versions (for Windows code, obvs)
deltarho[1859]
Posts: 4317
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: Uinteger<32>

Post by deltarho[1859] »

Thanks, adeyblue.

Both of those bis are a bit heavy for a newcomer. They are a bit heavy for me. :)

Perhaps I should call my bi IntDataTypesLite.bi. :lol:
SamL
Posts: 58
Joined: Nov 23, 2019 17:30
Location: Minnesota

Re: Uinteger<32>

Post by SamL »

nice Defines.
it would be nice to have a uint128, I'm sure I could find some where to use it.
deltarho[1859]
Posts: 4317
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: Uinteger<32>

Post by deltarho[1859] »

Yeah, I thought that I was onto something until adeyblue pointed out stdint.bi and basetsd.bi which I had never seen before. It reminds of Isaacc Newton (born 4 January 1643) and Gottfried Wilhelm Leibniz (born 1 July 1646) who both invented Calculas at pretty much the same time. Remarkably, neither of them knew what the other was up to. In the end, Newton got the credit.

I will buy into my 'Lite' version for my code, as I find Uint64 more readable than Ulongint for example.
dodicat
Posts: 7995
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Uinteger<32>

Post by dodicat »

You don't need to search the help files, do it the easy way
write into your ide
dim as uinteger i
then put your cursor over uinteger and press F1
deltarho[1859]
Posts: 4317
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: Uinteger<32>

Post by deltarho[1859] »

The explicit bit size is only mentioned in the description for Integer and Uinteger.

I have put uint64 and so on into WinFBE's FreeBASIC Keywords list so that they get syntax highlighted. :)
dodicat
Posts: 7995
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Uinteger<32>

Post by dodicat »

Deltarho.
Anything to do with integer gives the bit sizes.
cuint for example.
I haven't seen much use of <bit> in code, although it is very explicit
e.g.

Code: Select all

var x=cuint<64>(1.844674407370955e+019)
print x
#print typeof(x)
sleep
 
I think uint64 will confuse users.
There is no mention of it in fb data types.
You are in effect doing a Dafhi.
deltarho[1859]
Posts: 4317
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: Uinteger<32>

Post by deltarho[1859] »

Ulong -> 32-bit unsigned integer
Ulongint -> 64-bit unsigned integer

Uint32 -> 32-bit unsigned integer
Uint64 -> 64-bit unsigned integer

FreeBASIC syntax isn't particularly intuitive.

How is Uint64 confusing?

On Googling, I see that Uint64 is used in .Net Framework.

Short -> 16-bit signed integer
Sint16 -> 16-bit signed integer

OK, I can see some cringing at that, but Sint16 is better than Integer<16> in my opinion. There is no mistaking what Sint16 is.

Microsoft would use int16 - signed, being implicit by not using a qualifying 'u'. We could drop the use of 's' in my bi. I'll stay with 's' – I prefer explicit over implicit, and why I never use Var.

My bi is small. It could be expanded, but I want to avoid ending up with the size that adeyblue pointed to.

I am not looking for converts here. I can understand why some would not touch my idea with a barge pole. On the other hand, I reckon some will think: “I like the look of that”.

It is definitely working for me, especially with WinFBE highlighting them; if I mistype they don't get highlighted.
dodicat wrote:You are in effect doing a Dafhi.

:) I have seen dafhi change datatype syntax, but from my perspective, the resulting code was less readable.
St_W
Posts: 1628
Joined: Feb 11, 2009 14:24
Location: Austria
Contact:

Re: Uinteger<32>

Post by St_W »

I agree that FreeBasic's default data type naming is a bit confusing and unintuitive. The reasons why it is like it is, are mostly only historic ones. I'd prefer (U)Int16/(U)Int32/(U)Int64 if there wasn't that history and existing applications. That would be less confusing and easier to understand. And aligns better with other modern programming languages.

I think that (U)Integer<n> is the best we can have while staying compatible with old, existing code. What you can do is to use that instead of longInt, short, etc.

sint16 sounds a bit strange, I'd prefer int16 and uint16 like in many other languages.
wallyg
Posts: 276
Joined: May 08, 2009 7:08
Location: Tucson Arizona

Re: Uinteger<32>

Post by wallyg »

I too have never been happy with the form of type declarations. So I declared a set of #Defines to make what I want and let FBC convert it to what it needs. Also, several other constructs like the old Algol Begin - EndBegin statements. You can customize the compiler to allow a much more friendly environment this way.

Wally
deltarho[1859]
Posts: 4317
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: Uinteger<32>

Post by deltarho[1859] »

St_W wrote:sint16 sounds a bit strange, I'd prefer int16 and uint16 like in many other languages.
I changed my mind on that and dropped the 's' so that it is now implicit.

I am now using:

Code: Select all

#ifndef Uint8
  #define Uint8 = Uinteger<8>
#endif
#ifndef Uint16
  #define Uint16 = Uinteger<16>
#endif
#ifndef Uint32
  #define Uint32 = Uinteger<32>
#endif
#ifndef Uint64
  #define Uint64 = Uinteger<64>
#endif
#define Uint3264 = Uinteger
#ifndef int8
  #define int8 = Integer<8>
#endif
#ifndef int16
  #define int16 = Integer<16>
#endif
#ifndef int32
  #define int32 = Integer<32>
#endif
#ifndef int64
  #define int64 = Integer<64>
#endif
#define int3264 = Integer
I then edited my WibFBE FreeBASIC Keywords list.
Post Reply