sawyl: (A self portrait)
2013-09-13 01:02 pm
Entry tags:

Interesting pre-processor problem

I've had a busy but enjoyably productive week sorting out glitches ahead of the next round of upgrades. Particularly satisfyingly, I've been able to resolve an 18 month-old problem with the following piece of Fortran:

program question
character (len=*), parameter :: s = '????'
end program question

This compiled successfully in most cases but when the code was pre-processed prior to compilation, it failed with an error that indicated that the string delimiter was missing. Sure enough when the pre-processed source code was dumped, it became clear that the string had been converted to:

s = '??^

Eventually, someone pointed me to the relevant bit of documentation that explained the problem: the ??' string just happened to match the one of the trigraphs automatically replaced by the C pre-processor, used by the Fortran compiler to prepare the source ahead of the compilation phase...