On UInteger

New to FreeBASIC? Post your questions here.
Post Reply
deltarho[1859]
Posts: 4292
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

On UInteger

Post by deltarho[1859] »

@MrSwiss

You kept coming at me but I wasn't budging.

The penny has just dropped with regard to UInteger.

Being told what to do is not enough for me - I need to know why.

This is how I see it now.

If we have a variable which should be 32 bit when running in 32 bit mode but 64 bit when running in 64 bit mode then UInteger is the correct datatype to use. We have nothing to do. Whichever compiler we invoke it will do everything for us.

On the other hand if we have a variable which should be ULong, say, whether in 32 bit or 64 mode then we should use ULong. Using UInteger in this case will give us a 64 bit variable in 64 bit mode which is not what we want.

I realised my misunderstanding when I compiled a library using the 32 bit compiler when using UInteger. The library would not link in 64 bit mode. If I compiled the library using the 64 bit compiler then it worked in 64 bit mode. However, I now have two libraries - one for 32 bit and one for 64 bit. On the other hand by changing UInteger to ULong, the 32 bit compiled library works in either 32 bit mode or 64 bit mode.

<Big smile>
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: On UInteger

Post by MrSwiss »

@deltarho[1859],

took a bit of patience ... ;-)
MrSwiss wrote:A UInteger only has the same size as a ULong in FBC 32bit ... 32bit.
In FBC 64, a UInteger is equal to a ULongInt ... 64bit.
Remember: never use U-/Integer,
if you want a fixed size: U-/Long = 32bit, U-/LongInt = 64bit (both compilers)
My comment in the Mersenne Twister thread, should have been a sufficient push, into the right direction ...

Prime example for ULong, is Color (always 32bit, in both compilers).
deltarho[1859]
Posts: 4292
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: On UInteger

Post by deltarho[1859] »

My comment in the Mersenne Twister thread, should have been a sufficient push, into the right direction ...
Well, clearly, it wasn't because the penny did not drop. To my mind your comment was more of a definition than an explanation of the differences.
Prime example for ULong, is Color (always 32bit, in both compilers).
We have now left definition territory and entered explanation territory.

This is the main reason why I often use 'Example usage' in my posts. Over the years I have seen many posts which publish source code and nothing else, a definition, leaving the reader perplexed as to how to use the code, an explanation. I have often been criticised over the years for writing lengthy posts but, to my mind, the better the explanation the better equipped the reader is in being able to edit the published source code for their own needs. Obviously, it is nice to see someone using my code as is but what is nicer, for me, is to see someone develop their own code from it. If they publish that then it may give me another idea. This, to my mind, is the essence of programming forums. Definitions are a requirement but their power is only unleashed with an explanation.

Yeah, I know - I can go on a bit - at times.<smile>
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: On UInteger

Post by MrSwiss »

OK, you could also call a U-/Integer, a dynamic Type (vs. static/fixed). (Which one is better?)

Language is also complicating explanations sometimes.
I'm a native German speaker ... English is business language only.

Technically speaking:
a U-/Integer is equal to the pointer-size of the compiler used (maybe too technical?).
deltarho[1859]
Posts: 4292
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: On UInteger

Post by deltarho[1859] »

OK, you could also call a U-/Integer, a dynamic Type (vs. static/fixed). (Which one is better?)
Well, I would call it problematic, in my case.<smile>

Why not just call it platform specific.
Language is also complicating explanations sometimes.
And in the same country. I am from North Yorkshire in Northern England. When I was a young fellow I got a job at the Ministry Of Defence in the South of England. On some Monday mornings someone would say to me: "You went home again last weekend." to which I replied "How do you know?". They said "Because I din't understand a word you just said". I apologised, switched into 'southern mode' and continued the conversation.
Technically speaking:
a U-/Integer is equal to the pointer-size of the compiler used (maybe too technical?).
Nope - spot on.

I tried studying German when at school. I was the best at speaking it but but the worst student. For some reason most folk whose first language is English find it difficult learning another language. It may be arrogance but I think that there is more to it than that.
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: On UInteger

Post by MrSwiss »

deltarho[1859] wrote:Why not just call it platform specific.
Nope - nothing to do with platform (WIN/LIN).
deltarho[1859]
Posts: 4292
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: On UInteger

Post by deltarho[1859] »

Nope - nothing to do with platform (WIN/LIN).
My bad. American is my second language.<laugh>

We could call it bit specific. Just joking.

Your technical definition should be the one used. It is not "too technical" - it is how a definition should be. An explanation may be required but we should not relax a definition to help. The APIs at MSDN are definitions. There are some explanations but precious few. I learned how to use the 'crypto' APIs by getting one GPF after another. it was only when the GPFs stopped did I understand the definitions. One explanation could be that I am not as bright as I used to be.
Post Reply