NVFortran: C preprocessor bug

Hello!

I have tried to compile the following code (fortran-77):

#define _SAD_ 4
      print *,
     $(4.eq._SAD_)
      end

Compilation options:

nvfortran -Mpreprocess test.f -E

That’s prints to stdout the following result:

# 1 "test.f"
# 2 "test.f"
      print *,
     $(4.eq._SAD_)
      end

So, _SAD_ macro was not expanded. At the same time, if one remove round brackets, the output will be the following:

$ nvfortran -Mpreprocess test.f -E
# 1 "test.f"
# 2 "test.f"
      print *,
     $4.eq.4
      end

That is expected.

NVFortran version:

$ nvfortran --version

nvfortran 24.3-0 64-bit target on x86-64 Linux -tp znver2
NVIDIA Compilers and Tools
Copyright (c) 2024, NVIDIA CORPORATION & AFFILIATES.  All rights reserved.

If you can, add a space between the “.” and “SAD” so it’s seen as a unique token.

Preprocessing is not part of the Fortran standard so each compiler may have slightly different implementations. Ours is similar to the “cpp” C preprocessor, which gives the same output:

% cpp test.F
# 0 "test.F"
# 0 "<built-in>"
# 0 "<command-line>"
# 1 "/usr/include/stdc-predef.h" 1 3 4
# 0 "<command-line>" 2
# 1 "test.F"

      print *,
     $(4.eq._SAD_)
      end
1 Like

Thank you! This is a solution for such cases. Luckily, it is only one place in our codebase.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.