Mirsad Todorovac wrote:
On Sat, 7 Jun 2003, Russell Whitaker wrote:
On Sat, 7 Jun 2003, Mirsad Todorovac wrote:
I apologize for replying to my own email, but is there a way to do this with GPC preprocessor, or is it on list of planned features?
{$if Low (Char) < 0} {$error "this won't work: negative Char used as index} {$endif}
Perhaps I'm wrong, but I thought by definition a Char cannot be negative.
Of course, it cannot. It's not even a number. So, if anything `Ord (Low (Char)) < 0' or `Low (Char) < Chr (0)' would work. But (a) it's always False, and (b) ...
OK, then the second one:
{$if BitSizeOf (LongestInt) > High (TString)} {$error "this won't work: on this platform LongestInt it too huuge ..."} {$endif}
... (apart from the fact that this check is really quite silly, as we've discussed privately) ...
Obviously, even now when I'm looking better, preprocessor may not know about SizeOf(), BitSizeOf(), High() and Low() of a user-defined type :-/ ?!?
... it does not know anything about Pascal. It's a *pre*processor!
You can do something like compile-time assertions by something like:
const AssertTWindowXYSize = 1 / Ord (CONDITION);
This will yield a division by zero and fail at compile time if the condition is false.
I've wondered if we should build in such a feature with some syntax, but I'm not sure if the syntax above or a new syntactic extension would be better ...
Frank