Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Macro expansion with "defined"

V-T
New Contributor I
314 Views

Consider the following example:

#define A 42                                                                                                                                                                                                
#define F(X) defined(X)&&X<137
#if F(A)
print*,A
#endif
end

The executable compiled with `gfortran` will print the number, while the executable from `ifx` (2025.0.0) will not. This difference is caused by the rules of macro expansion that are not defined by the Fortran standard. The ability to include `defined` in macros is convenient, since repeating `#if` statements with complex expressions can be shortened. Since the preprocessor in `ifx` is not error-free, I'd like to ask, if it is the intended behavior and what is the reason for these macro expansion rules.

0 Kudos
1 Reply
V-T
New Contributor I
273 Views

This is only a minimal example to keep the question short. I'm aware that the task in this example can be achieved by different means. In my real project (which I will not be posting here), the use of `defined` inside macros can significantly simplify the code and avoid error-prone repetitions. You cannot judge the need of this feature or the complexity of the project I'm working on by analyzing this example. Furthermore, your comment neither answers my question nor does it in any way help to clarify this matter.

0 Kudos
Reply