[comp.lang.ada] limitations on optimizers for conditional compilation

emery@MBUNIX.MITRE.ORG (Emery) (12/11/89)

Armin points out that it is perfectly legal to do conditional
compilation of statements based on some (constant) boolean value.
This is something I'd expect a good compiler to do, and a technique
that I have used (sending prayers to the God of Compilers that my
compiler was "good").   

Where this approach fails, though, is in non-statements such as type
declarations.  It would be nice to have support for this:
	type foo_bar is 
	  record
	    x : integer;
#ifdef VAX
	    y : float_64;
#elsif IBM_PC_WITH_8087
	    y : IEEE_float;
#endif
	end record;

I suspect that the very clever person could use variant records for
this example, but I also suspect that it wouldn't take much to come up
with type definitions where a variant record approach wouldn't work.

Using these ("constant type") variant records would probably make the
program harder to read, because it wouldn't be clear to the maintainer
if this was a variant record object (or subtype) based on some 'real
variant) or based on some conditional compilation feature.  Objects
are often widely separated from their declaration, compared to
(optimizable) conditional compilation statements.
				dave 
				emery@aries.mitre.org

munck@linus.UUCP (Robert Munck) (12/12/89)

In article <8912110202.AA11909@mbunix.mitre.org> emery@MBUNIX.MITRE.ORG (Emery) writes:
>... (discusses conditional compiliation of executable code)...   
>
>Where this approach fails, though, is in non-statements such as type
>declarations.  It would be nice to have support for this:
>	  record
>#ifdef VAX
>	    y : float_64;
>#elsif IBM_PC_WITH_8087
>	    y : IEEE_float;
>#endif
>
>... but I also suspect that it wouldn't take much to come up
>with type definitions where a variant record approach wouldn't work.

I'm not so sure about this anymore.  I have a feeling that "type
definitions where a variant record approach wouldn't work" may well be
the equivalent of "programs where structured coding doesn't work."

We oldtimers are all used to playing fast and loose with the source text
with preprocessor statements, including such horrors as "manufacturing"
keywords from conditionals and compile-time variables.  Maybe, just
maybe, that isn't such a good idea, and the good software engineering
practice would be to stick to the language definition, variant records
and all.

I have only one data-point, a small OS with a fair number of "sysgen"
variables and choices.  I found it fairly easy and "satisfactory to my
esthetic sense" to do everything entirely within the language.