Chris Burrows
2010-08-13 00:00:59 UTC
I have never been a fan of the system used in some Pascal / Modula-2
compilers where special comments e.g. (*$IFDEF TrialVersion *)are used in
the source code as a conditional compilation mechanism. It has always seemed
'clunky' and particularly non-portable to me.
During a recent discussion in the Oberon newgroup I pointed out that there
is actually no need, in simple cases, for an additional language feature. It
is feasible for a compiler to generate absolutely no code for statements
that could be statically evaluated to:
IF FALSE THEN .... END;
If you were using a compiler that eliminates such code you could implement a
simple module with your various conditions defined. For example:
MODULE Options;
CONST
TrialVersion = TRUE;
....
....
Then e.g. wherever you wanted to *eliminate all traces* from your executable
file of any features related to your full version you could write:
IF (Options.TrialVersion) THEN ....
At build-time you would link in the appropriate version of the Options
object file related to the version that is being built. (We use the
excellent FinalBuilder tool to automate this sort of process).
Purely coincidentally, I was pleasantly surprised a few days later to
discover that the code-generator for the original Lilith Modula-2 compiler
from the 1980's provides for conditional compilation in this way. Do other
Modula-2 compilers have this particular feature?
Regards,
Chris Burrows
CFB Software
http://www.cfbsoftware.com/modula2
compilers where special comments e.g. (*$IFDEF TrialVersion *)are used in
the source code as a conditional compilation mechanism. It has always seemed
'clunky' and particularly non-portable to me.
During a recent discussion in the Oberon newgroup I pointed out that there
is actually no need, in simple cases, for an additional language feature. It
is feasible for a compiler to generate absolutely no code for statements
that could be statically evaluated to:
IF FALSE THEN .... END;
If you were using a compiler that eliminates such code you could implement a
simple module with your various conditions defined. For example:
MODULE Options;
CONST
TrialVersion = TRUE;
....
....
Then e.g. wherever you wanted to *eliminate all traces* from your executable
file of any features related to your full version you could write:
IF (Options.TrialVersion) THEN ....
At build-time you would link in the appropriate version of the Options
object file related to the version that is being built. (We use the
excellent FinalBuilder tool to automate this sort of process).
Purely coincidentally, I was pleasantly surprised a few days later to
discover that the code-generator for the original Lilith Modula-2 compiler
from the 1980's provides for conditional compilation in this way. Do other
Modula-2 compilers have this particular feature?
Regards,
Chris Burrows
CFB Software
http://www.cfbsoftware.com/modula2