Hi, everybody!
How could I make this preprocessor check work?
domac:~/pascal/gcc-3.2.1/gcc/p/test> time make MASK='mtm017.pas' pascal.check-long rm -f *.dat *.o *.s *.i *.gpi *.gpd *.gpc core a.out stderr.out *.exe testmake.tmp dummy.c dummy.pas dummy.out diff_cr*.tmp fixcr fixcr.exe rm -f todo/a.out todo/*.exe todo/*.o todo/*.s todo/*.i todo/*.gpi todo/*.gpd todo/core { gpc --version | head -1; gpc --print-search-dirs | grep install | head -1; hostname || echo "unknown host"; date "+%Y-%m-%d %H:%M:%S"; } | \ sed -e 's,^,Testing ,;N;s,\n.*gcc-lib[/], (,;s,[/].*,),;N;s,\n, (,;s,$,),;N;s/\n/, /' Testing gpc 20030507, based on gcc-3.2.1 (i686-pc-linux-gnu) (domac), 2003-06-07 15:36:13 echo "gpc -g -O3 -W -Wall -Wundef -Wpointer-arith -Wno-unused " gpc -g -O3 -W -Wall -Wundef -Wpointer-arith -Wno-unused PC="gpc" PFLAGS="--autobuild -g -O3 -W -Wall -Wundef -Wpointer-arith -Wno-unused " SRCDIR="." TEST_MAKE_FLAG=test-make-flag "./test_run" mtm017.pas | tee test_log GPC-TEST-BEGIN ========================== TEST mtm017.pas: ./mtm017.pas:23: conditional expression: `Low' is not defined ./mtm017.pas:23: conditional expression: trailing garbage failed
--------------------------------------------------------------------------------- function IsValidNumberBase2 (s: String; Base: Integer): Boolean; attribute(const); var i, dv : Integer; attribute (register); b : Byte; attribute (register); function DigitValue (Dig: Char): Integer; attribute (inline, const); var d : Integer; attribute (register); {$if Low (Char) < 0} {$error "this won't work: negative Char used as index} {$endif} v : array [0..255] of Integer = ( -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, -1, -1, -1, -1, -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 );
begin DigitValue := v[Dig]; end;
...
Thanks, Mirsad
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}
The other, more obvious need for such use would be:
{$if BitSizeof (LongestInt) > High (TString)} {$error "the type can't be represented with TString string type. program won't compile on this architecture"} {$endif}
I'm sorry if this has been discussed recently. Thank you very much in forward.
Best regards, Mirsad
P.S. The program bellow has two obvious errors, I posted a development snapshot in a rush.
Mirsad Todorovac wrote:
Hi, everybody!
How could I make this preprocessor check work?
domac:~/pascal/gcc-3.2.1/gcc/p/test> time make MASK='mtm017.pas' pascal.check-long rm -f *.dat *.o *.s *.i *.gpi *.gpd *.gpc core a.out stderr.out *.exe testmake.tmp dummy.c dummy.pas dummy.out diff_cr*.tmp fixcr fixcr.exe rm -f todo/a.out todo/*.exe todo/*.o todo/*.s todo/*.i todo/*.gpi todo/*.gpd todo/core { gpc --version | head -1; gpc --print-search-dirs | grep install | head -1; hostname || echo "unknown host"; date "+%Y-%m-%d %H:%M:%S"; } | \ sed -e 's,^,Testing ,;N;s,\n.*gcc-lib[/], (,;s,[/].*,),;N;s,\n, (,;s,$,),;N;s/\n/, /' Testing gpc 20030507, based on gcc-3.2.1 (i686-pc-linux-gnu) (domac), 2003-06-07 15:36:13 echo "gpc -g -O3 -W -Wall -Wundef -Wpointer-arith -Wno-unused " gpc -g -O3 -W -Wall -Wundef -Wpointer-arith -Wno-unused PC="gpc" PFLAGS="--autobuild -g -O3 -W -Wall -Wundef -Wpointer-arith -Wno-unused " SRCDIR="." TEST_MAKE_FLAG=test-make-flag "./test_run" mtm017.pas | tee test_log GPC-TEST-BEGIN ========================== TEST mtm017.pas: ./mtm017.pas:23: conditional expression: `Low' is not defined ./mtm017.pas:23: conditional expression: trailing garbage failed
function IsValidNumberBase2 (s: String; Base: Integer): Boolean; attribute(const); var i, dv : Integer; attribute (register); b : Byte; attribute (register); function DigitValue (Dig: Char): Integer; attribute (inline, const); var d : Integer; attribute (register); {$if Low (Char) < 0} {$error "this won't work: negative Char used as index} {$endif} v : array [0..255] of Integer = ( -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, -1, -1, -1, -1, -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 );
begin DigitValue := v[Dig]; end;
...
Thanks, Mirsad
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.
Russ
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.
OK, then the second one:
{$if BitSizeOf (LongestInt) > High (TString)} {$error "this won't work: on this platform LongestInt it too huuge ..."} {$endif}
Obviously, even now when I'm looking better, preprocessor may not know about SizeOf(), BitSizeOf(), High() and Low() of a user-defined type :-/ ?!?
Mirsad
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
On Sun, 8 Jun 2003, Frank Heckenbach wrote:
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; I'm still fresh from C. Excuse my ignorance ...
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) ...
Particular example, sure. In general, it would be nice to check for "impossible" prerequisites. This just reminded me of an Arriane counter that "possibly couldn't go over 32767" (or something) ;-) ...
Generally, and theoretically, when I'm writting part of unit/library, I can't know in advance what it should be running on. Pehaps there are machines with BitSizeOf (LongestInt) > High (TString) = 2048 already ...
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!
Of course.
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.
Clever.
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 ...
The first thought is a macro
{$define CompileTimeAssert(x) (1 / Ord (x))}
but it could be used only as a function assigned to a dummy constant.
Mirsad
Mirsad Todorovac wrote:
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) ...
Particular example, sure. In general, it would be nice to check for "impossible" prerequisites. This just reminded me of an Arriane counter that "possibly couldn't go over 32767" (or something) ;-) ...
Yes, I remember that. But I suppose it wouldn't have been caught at compile time. Any a runtime abort would not have been very helpful, either. ;-)
Generally, I'm very skeptical of "can't happen"s. But this one is really absurd, as I explained.
Generally, and theoretically, when I'm writting part of unit/library, I can't know in advance what it should be running on. Pehaps there are machines with BitSizeOf (LongestInt) > High (TString) = 2048 already ...
Definitely not. GCC's internals are such that it can't handle integers larger than 64 or 128 bits (not sure exactly) at all.
Frank