PDA

View Full Version : Optional debug code -- How to do it?


vic_kelson
09-16-2004, 10:30 PM
Love the forums, love the compiler -- long time reader, first-time poster. Sorry for the long post, but I've never really seen this discussed.

I have a LOT of assertion logic in my large F95 program that is very useful for debugging during program development, but costly in execution time (;) I took a seminar from Bertrand Meyer once and precondition/postcondition testing has saved me a LOT of work in F95 code). I <u>hate</u> to remove it of course, because it serves me well during development, but I need to make it optional. My code is freely available, and I have striven for years to keep it as portable as I can.

So. What is the best way to optionally compile this code? I'm an old 1977-present Fortran geezer (my current codes are very object-oriented!), so I remember the good old 'D in column 1' trick; that *sigh* is not available for free-form F95, and I can't remember if it was in the F77 standard or not. Is there a free-format way to do that? I've never found one. It would be a simple trick, e.g. !$DEBUG or some such syntax on debug lines. I <u>guess</u> I could implement a preprocessor, but *ugh* it's nonstandard.

I saw the undocumented feature of running <i>cpp</i> from LF95 in the FAQ. This is OK, but (1) not standard F95 and potentially unportable, (2) not quite as Fortran-friendly as <i>fpp</i>, and (3) as a matter of principle, I don't use undocumented features of compilers -- been there, done that. Also, I've put <i>cpp</i> tags in and taken them out of the code because of incompatibility with some compilers (in particular LF 5.7 Express for Windows -- never could get the makefile right with Mingw's <i>gcc</i>). I might like to use <i>fpp</i>, if there's a way to use it in Visual Studio. Incidentally, how do I set a compile-time variable (e.g. -D_DEBUG_ in Unixy systems) in Visual Studio? Personally, I think that <i>cpp</i> and <i>fpp</i> are kind of kludgy for Fortran -- it just doesn't look... <i>Fortranny</i> to me, and I like the way Fortran looks.

I want to do something that is portable and will work in the future with no/minimal maintenance. IMHO, the folks who designed the Fortran standard have been shortsighted in not standarizing a syntax for conditional compilation and I'm sure they don't expect us all to count on <i>cpp</i> (is there a cultural problem? nobody does this? too many people already using <i>cpp</i>?). I've looked and looked for a good solution to this problem, on the web and elsewhere, so I might be missing something...

What should I do?

Advice is much appreciated!
--vic