Optimisation through Directives


Those wishing to cling to C often, correctly, claim that with compiler directives anything is possible. However, the result tends to be less than portable or even reliable.

Many compilers can be told to assume that the C is `clean' and that heavy optimisation will not break the code by a variety of command-line options, #pragmas and compiler-parsed comments. These rarely produce portable optimisation, and they require a good understanding of the machine architecture in order to use them safely -- if one is overly enthusiastic with them, the code will give wrong answers, but perhaps only sometimes, and rarely when compiled with debugging flags on...

The effort of reading code sufficiently carefully to know where these directives can safely be placed is often greater than that involved in rewriting it in FORTRAN. The alternative, of adding directives until the answer changes, can be very dangerous, for overenthusiastic directives will lead to code suddenly failing after a minor compiler upgrade or a change in the wind dierction.

Of course C with directives is a solution, and marginally easier and more portable than writing directly in assembler. However, ideal it is not.


MJ Rutter, August 2000. Return to contents