According to the PureBasic.pdf docs (page 358)
A long is ALWAYS 4 bytes
An integer is 4 bytes on 32-bit CPUs and 8 bytes on 64-bit machines
...and the default type is integer, meaning you don't know if it is 4 or 8 bytes (technically) So for all of my handles, I probably should have been using 8 bytes because I'm on a 64-bit machine, but long is locked to 4, unless docs are wrong
CreateThread Procedure corrupting strings
Re: CreateThread Procedure corrupting strings
Yup; I was wrong. (I had it the other way around; working with a 32bit app right now)
Sorry for the mis-information.
Code: Select all
Debug SizeOf(long)
Debug SizeOf(integer)
Re: CreateThread Procedure corrupting strings
I have just a few comments. These things should reasonably be known after reading only a small portion of the documentation for PureBasic.sc4pb wrote: ↑Thu Jun 08, 2023 2:42 am Awww nuts, stupid question time.
For PureBasic built in library procedures that return "handles" to things, you know databases, images, memory blocks whatever, what data type should I be using? I just realized as I was looking over the docs that I was mistaken about something.
https://www.purebasic.com/documentation/reference/general_rules.htmlExcerpt from General Synrax Rules wrote:- Return values of commands are always Integer if no other type is specified in the Syntax line of the command description.
Yes you should be using integers. Historically, the integer type was created as a separate type about the time when 64-bit compilations first became available. Previous to that all handles were longs. Older code and possibly some examples in the documentation may have been written with longs used to hold object handles.Many examples in docs utilize variables that are not declared, just generated on the fly. And if no type is specified, for some reason I thought the default type was "long" (4 bytes). Now I see the default type is "integer", which can be either 4 or 8 bytes depending on 32 or 64 bit processor.
Well ok, for all of my calls with handles, like AllocateMemory and OpenDatabase, I've been using longs. So...
...but this is wrong, right? I should have been using integers?Code: Select all
Define handle.l handle=AllocateMemory(1000)
https://www.purebasic.com/documentation/reference/define.htmlExcerpt from documentation for Define wrote:Without this keyword, variables are created with the default type of PureBasic which is the type INTEGER. As a reminder, the type INTEGER is:
4 bytes (with a 32-bit compiler) ranging from -2147483648 to + 2147483647
8 bytes (with a 64-bit compiler) ranging from -9223372036854775808 to +9223372036854775807
I have no opinion on your feature request. EnableExplicit was added in v4.00 and may benefit from some additional options.I bring this up because of another big gripe of mine:
I won't write a line of code without EnableExplicit. But in my mind EnableExplicit should require both a variable declaration AND a type declaration. So when explicit:
I've had a number of bugs that have been hard to track down because I failed to add a type to a variable declaration.Code: Select all
Define foo ; this should be REJECTED by EnableExplicit, there is no type Define foo.s ;this is fine, it's a string.
Is there way to require a type? Or in other words, to disable the default behavior of PureBasic assuming variables are integers?