At 10:38 AM +0800 26/6/03, Peter N Lewis wrote:but that does not work in GPC. My solution has been to use a prefix file and copy all such macro definitions to the prefix file. This is less than ideal since it breaks the modularity. Perhaps someone has a better solution for me, but it's the best I can come up with so far.
Forgive me for a rambling a few thoughts on this.
I haven't time to test this, but how does it go if a procedure does no productive activity - does the compiler strip the procedure and its calls out? (i.e. detecting an empty procedure body.) Have a constant, something like:
const doAsserts = false ;
and somewhere in the code calling your own assert defined like:
procedure assert( ... ) begin if doAsserts then begin end end
Would the compiler recognise that the above procedure is useless (when doAsserts = true) and strip out the calls to new assert() procedure ?
(Of course you could also pass the state as a variable and we can all argue about use of globals, etc. In this case the compiler needs to recognise that the variable in fact has a constant value, etc.)
On the same lines you could have your assert() as a function yielding a constant value (false), which the compiler can strip out if it sees:
dummyVar = assert( something ) ;
Like Peter some of my asserts call very expensive functions, so stripping them out in production code is essential.
A possible compromise might be to have GPC continue as-is, but for Peter to put the if's into his testing routines, the ones called by GPCs' assert, e.g.:
Assert( ValidDataStructure( thingy ) );
with assertions off becomes:
DummyVar := ValidDataStructure( thingy ) ;
but ValidDataStructure() contains an 'if' on a constant, which causes the procedure body to be empty, which the compiler then strips... (or doesn't if it can't do this).
This won't cater for everything (for example an assertion on an expression), but it might be OK for the more expensive things since they are likely to be function calls anyway - ?
Just while I'm writing: over-and-above the usual '#if debug' type of thing, my C debugging/assert/etc. routines pass variables that have four-states for this and other forms of testing (always, never, onTrue and onFalse). Usually these are effectively and'ed with another variable, e.g. the result of the assert or a global control variable such as doAsserts. This way the caller has control over individual asserts.
Grant