program untitled;
{$mode objfpc}{$R+}
I have a question about the this ^. In the document you linked you always add the $mode after
program, on my example I placed it before, does it make a difference, isn't it global?
I also noticed you used {R+} after the program. In the docs, it says that directives like R are set until the are unset or end of unit;
So if I wanted to restrict it to a certain region, i guess I'd have to do {R+} ... {R-}. Correct?
I also saw, in the docs, this example:
{$BITPACKING ON}
Type
TMyRecord = packed record
B1,B2,B3,B4 : Boolean;
end;
I'm guessing the directive ends on "end;" But does it, shouldn't it follow the above requirements?
I think this is related hence the question.
Now back to my original post, your piece on avoiding range error and overflows is great, but it doesn't really solve my problem.
The real scenario for what my example was simulating, is a situation where you receive a variable, that you have no control over, and you expect it to be a positive value, but it's actually a negative value, you don't know it and it screws your system. There are lots of unexpected bugs like that in c/c++, and sure you can clearly catch it at runtime, and now I know a lot more about how to do it in pascal.
But my statement about
strictness was about language design, and that in my view, ideally, operations between signed and unsigned should not be permitted at all. Actually, if you ask me, I think no auto conversions should happen ever, if you wanna add a uint8 to a uin16, in a uint32, that's you problem, you call the functions to convert them. Of course that's not how modern languages work, I guess for convenience. And if we analise the design that pascal takes(based on the docs listed above, about the base types), it's(the compiler) clearly trying to make sure that all operations will execute, as correctly as possible, to the limit of it's ability.
Thanks again for all the responses, and feel free to correct me on anything if you think I'm wrong.