@@ -178,39 +178,42 @@ In the case of gfortran, this appears to have been resolved by default starting
178178
179179#### Line breaks in macro invocations
180180
181- As mentioned above, preprocessor macro invocations are always expanded to a
182- single line, no matter how many lines were used by the invocation. This means
183- it's problematic to invoke the ` call_assert* ` macros with code like the
184- following:
181+ The preprocessor is not currently specified by any Fortran standard, and
182+ as of 2024 its operation differs in subtle ways between compilers.
183+ One way in which compilers differ is how macro invocations can safely be broken
184+ across multiple lines.
185+
186+ For example, gfortran and flang-new both accept backslash ` \ ` continuation
187+ character for line-breaks in a macro invocation:
185188
186189``` fortran
187- ! INCORRECT: don't use & line continuations!
188- call_assert_diagnose( computed_checksum == expected_checksum, &
189- "Checksum mismatch failure!", &
190+ ! OK for flang-new and gfortran
191+ call_assert_diagnose( computed_checksum == expected_checksum, \
192+ "Checksum mismatch failure!", \
190193 expected_checksum )
191194```
192- When the preprocessor expands the macro invocation above, the ` & ` characters
193- above are not interpreted as Fortran line continuations. Instead they are
194- inserted into the middle of the single-line macro expansion, where they will
195- (likely) create a confusing syntax error.
196195
197- Instead when breaking long lines in a macro invocation, just break the line (no
198- continuation character!), eg :
196+ Whereas Cray Fortran wants ` & ` line continuation characters, even inside
197+ a macro invocation :
199198
200199``` fortran
201- ! When breaking a line in a macro invocation, use backslash `\` continuation character:
202- call_assert_diagnose( computed_checksum == expected_checksum, \
203- "Checksum mismatch failure!", \
200+ ! OK for Cray Fortran
201+ call_assert_diagnose( computed_checksum == expected_checksum, &
202+ "Checksum mismatch failure!", &
204203 expected_checksum )
205204```
206205
206+ There appears to be no syntax acceptable to all compilers, so when writing
207+ portable code it's probably best to avoid line breaks inside a macro invocation.
208+
209+
207210#### Comments in macro invocations
208211
209212Fortran does not support comments with an end delimiter,
210- only to-end-of-line comments. As such, there is no way to safely insert a
213+ only to-end-of-line comments. As such, there is no portable way to safely insert a
211214Fortran comment into the middle of a macro invocation. For example, the
212215following seemingly reasonable code results in a syntax error
213- after macro expansion:
216+ after macro expansion (on gfortran and flang-new) :
214217
215218``` fortran
216219! INCORRECT: cannot use Fortran comments inside macro invocation
@@ -220,7 +223,7 @@ call_assert_diagnose( computed_checksum == expected_checksum, ! ensured since ve
220223```
221224
222225Depending on your compiler it * might* be possible to use a C-style block
223- comment (because they are removed by the preprocessor), for example with
226+ comment (because they are often removed by the preprocessor), for example with
224227gfortran one can instead write the following:
225228
226229``` fortran
0 commit comments