[PATCH,fortran] Add pre-defined macros for different available types
Jerry DeLisle
jvdelisle@charter.net
Sat Dec 29 00:41:00 GMT 2018
OK Steve,
Jerry
On 12/28/18 10:43 AM, Steve Kargl wrote:
> Ping.
>
> On Tue, Dec 25, 2018 at 01:44:10PM -0800, Steve Kargl wrote:
>> Here's a Holiday present for Fortranners.
>>
>> 2018-12-25 Steven G. Kargl <kargl@gcc.gnu.org>
>>
>> * cpp.c (gfc_cpp_init): Add pre-defined macros for INTEGER(1)
>> INTEGER(2), INTEGER(8) and INTEGER(16) if supported. Add pre-defined
>> macros for REAL(10) and REAL(16) if available.
>> * gfortran.texi: Document new macros.
>>
>> As a Fortran compiler is required to have default integer kind,
>> default real kind, and double precision, I did not include macros
>> for these types (ie., there are no __GFC_INTEGER_4__, __GFC_REAL_4__,
>> and __GFC_REAL_8__).
>>
>> This allows code like
>>
>> % cat a.F90
>> program foo
>> #ifdef __GFC_REAL_16__
>> real(16) x
>> x = 1
>> print *, x
>> #endif
>> end program foo
>> % gfcx -o z a.F90 && ./z
>> 1.00000000000000000000000000000000000
>>
>> --
>> Steve
>
>> Index: gcc/fortran/cpp.c
>> ===================================================================
>> --- gcc/fortran/cpp.c (revision 267418)
>> +++ gcc/fortran/cpp.c (working copy)
>> @@ -570,6 +570,8 @@ void
>> gfc_cpp_init (void)
>> {
>> int i;
>> + gfc_integer_info *int_info;
>> + gfc_real_info *real_info;
>>
>> if (gfc_option.flag_preprocessed)
>> return;
>> @@ -607,6 +609,26 @@ gfc_cpp_init (void)
>> else if (opt->code == OPT_MT || opt->code == OPT_MQ)
>> deps_add_target (cpp_get_deps (cpp_in),
>> opt->arg, opt->code == OPT_MQ);
>> + }
>> +
>> + for (int_info = gfc_integer_kinds; int_info->kind != 0; int_info++)
>> + {
>> + if (int_info->kind == 1)
>> + cpp_define (cpp_in, "__GFC_INT_1__=1");
>> + if (int_info->kind == 2)
>> + cpp_define (cpp_in, "__GFC_INT_2__=1");
>> + if (int_info->kind == 8)
>> + cpp_define (cpp_in, "__GFC_INT_8__=1");
>> + if (int_info->kind == 8)
>> + cpp_define (cpp_in, "__GFC_INT_16__=1");
>> + }
>> +
>> + for (real_info = gfc_real_kinds; real_info->kind != 0; real_info++)
>> + {
>> + if (real_info->kind == 10)
>> + cpp_define (cpp_in, "__GFC_REAL_10__=1");
>> + if (real_info->kind == 16)
>> + cpp_define (cpp_in, "__GFC_REAL_16__=1");
>> }
>>
>> if (gfc_cpp_option.working_directory
>> Index: gcc/fortran/gfortran.texi
>> ===================================================================
>> --- gcc/fortran/gfortran.texi (revision 267418)
>> +++ gcc/fortran/gfortran.texi (working copy)
>> @@ -418,9 +418,17 @@ statement, the included file is not preprocessed. To
>> files, use the equivalent preprocessor statement @code{#include}.
>>
>> If GNU Fortran invokes the preprocessor, @code{__GFORTRAN__}
>> -is defined and @code{__GNUC__}, @code{__GNUC_MINOR__} and
>> +is defined. The macros @code{__GNUC__}, @code{__GNUC_MINOR__} and
>> @code{__GNUC_PATCHLEVEL__} can be used to determine the version of the
>> compiler. See @ref{Top,,Overview,cpp,The C Preprocessor} for details.
>> +
>> +GNU Fortran supports a number of @code{INTEGER} and @code{REAL} kind types
>> +in additional to the kind types required by the Fortran standard.
>> +The availability of any given kind type is architecture dependent. The
>> +following pre-defined preprocessor macros can be used to conditional
>> +include code for these additional kind types: @code{__GFC_INTEGER_1__},
>> +@code{__GFC_INTEGER_2__}, @code{__GFC_INTEGER_8__}, @code{__GFC_INTEGER_16__},
>> +@code{__GFC_REAL_10__}, and @code{__GFC_REAL_16__}.
>>
>> While CPP is the de-facto standard for preprocessing Fortran code,
>> Part 3 of the Fortran 95 standard (ISO/IEC 1539-3:1998) defines
>
>
More information about the Fortran
mailing list