Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion ompvv/ompvv.F90
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,16 @@
#define OMPVV_TEST(condition) call test_error(condition, __FILENAME__, __LINE__)

! Macro for testing for errors
#define OMPVV_TEST_VERBOSE(condition) call test_error_verbose(condition, "condition", __FILENAME__, __LINE__)
#ifdef __GFORTRAN__
! gfortran invokes cpp in traditional mode that does not support the # operator.
! Use the stringify method suggested by its manual:
! https://gcc.gnu.org/onlinedocs/cpp/Traditional-macros.html
#define OMPVV_STRINGIFY(x) "x"
#define OMPVV_TEST_VERBOSE(condition) call test_error_verbose(condition, OMPVV_STRINGIFY(condition), __FILE__, __LINE__)
#else
! Assume ISO Standard C compliant preprocessor
#define OMPVV_TEST_VERBOSE(condition) call test_error_verbose(condition, #condition, __FILENAME__, __LINE__)
Copy link
Collaborator

@andrewkallai andrewkallai Dec 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#define OMPVV_TEST_VERBOSE(condition) call test_error_verbose(condition, #condition, __FILENAME__, __LINE__)
#ifdef __GFORTRAN__
#define STR(x) "x"
#define OMPVV_TEST_VERBOSE(condition) call test_error_verbose(condition, STR(condition), __FILENAME__, __LINE__)
#else
#define OMPVV_TEST_VERBOSE(condition) call test_error_verbose(condition, #condition, __FILENAME__, __LINE__)
#endif

Copy link
Collaborator

@andrewkallai andrewkallai Dec 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change line 86 to

#ifdef __GFORTRAN__
#define STR(x) "x"
#define OMPVV_TEST_AND_SET_VERBOSE(err, condition) err = err + test_and_set_verbose(condition, STR(condition), __FILENAME__, __LINE__)
#else
#define OMPVV_TEST_AND_SET_VERBOSE(err, condition) err = err + test_and_set_verbose(condition, #condition, __FILENAME__, __LINE__)
#endif

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andrewkallai Can you try whether changing #condition to "condition " #condition works for gfortran and other compilers? The preprocessor is supposed to expand #condition to the value of condition wrapped in double quotes, and then the resulting constant is concatenated with the adjacent string constant. As I know the concatenation is optional, but let's try whether this trick works or not.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GNU cpp's manual suggests a way to stringize using the traditional cpp:
image

It indeed seems to work: https://godbolt.org/z/jWKGrnffc

#endif

! Macro for setting errors on condition
#define OMPVV_TEST_AND_SET(err, condition) err = err + test_and_set(condition, __FILENAME__, __LINE__)
Expand Down