Helpfile - specify the actual DATATYPE instead of "a number"
Posted: Thu Sep 03, 2015 8:45 am
In just about every page of the helpfile for Return Value it simply says something like "The return value is a number".
I find this vagueness perplexing because I don't see it being any harder to document whether this "number" is a "Long", "Quad", hybrid 32/64 "Integer", or otherwise, and it's simply asking for trouble forcing the programmer to guess or wasting their time forcing them to experiment/disassemble if they need to be pushing 32 or 64bits onto the stack. Likewise there's no mention of signed or unsigned. This is what documentation is for, and it when it comes to the datatype being returned I thought this was fundamental in getting the code right!?
And no you certainly can't "just use Integer for everything" - FileSize() for one example always needs a Quad, and never a Long or Integer if you always want correct results on both x86 & x64, but the PB compiler will let you use a Long with FileSize(), and it'll usually work until you try a 4GB+ file, in which case it'll either crash or return invalid result.
Try OpenFile() with a Long in Windows-32 and it'll work, again the compiler won't complain or give you a hint, but your code will crash in 64bit Mac and Linux - the handle needs to be hybrid Integer.
How many of these .Q's, .L's, and .I's i've gotten wrong in my source code I have no idea for these reasons, and I'm forced to assume that "if it doesn't crash i've probably chosen the right one"... yet impossible to be confident.
I find this vagueness perplexing because I don't see it being any harder to document whether this "number" is a "Long", "Quad", hybrid 32/64 "Integer", or otherwise, and it's simply asking for trouble forcing the programmer to guess or wasting their time forcing them to experiment/disassemble if they need to be pushing 32 or 64bits onto the stack. Likewise there's no mention of signed or unsigned. This is what documentation is for, and it when it comes to the datatype being returned I thought this was fundamental in getting the code right!?
And no you certainly can't "just use Integer for everything" - FileSize() for one example always needs a Quad, and never a Long or Integer if you always want correct results on both x86 & x64, but the PB compiler will let you use a Long with FileSize(), and it'll usually work until you try a 4GB+ file, in which case it'll either crash or return invalid result.
Try OpenFile() with a Long in Windows-32 and it'll work, again the compiler won't complain or give you a hint, but your code will crash in 64bit Mac and Linux - the handle needs to be hybrid Integer.
How many of these .Q's, .L's, and .I's i've gotten wrong in my source code I have no idea for these reasons, and I'm forced to assume that "if it doesn't crash i've probably chosen the right one"... yet impossible to be confident.
