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

compiler appears to ignore my integer(8) declaration

michaelgreen1
Beginner
2,052 Views

Hi All,

 

Why does this code:

integer(8)      delta

delta = 2654435769

 

always produce this warning?

warning #8221: This integer constant is outside the default integer range - using INTEGER(8) instead. [2654435769]

 

Many thanks

Mike

0 Kudos
4 Replies
Arjen_Markus
Honored Contributor I
2,042 Views

The constant that you specify is a default integer, so quite probably 4 bytes with a maximum value of 2**31-1. Use an explicit kind instead:

delta = 2654435769_8

 

(And you can use the code formatting feature - the ... and then </>. That preserves the formatitng, which make sreading longer code much easier)

0 Kudos
MWind2
New Contributor III
2,012 Views

I would not pretend to know if the warning is technically correct fortran, but I find it less than I would expect . 

I would hope that it would check assignments from the RHS with the LHS type and not what it finds on the RHS without context.

0 Kudos
FortranFan
Honored Contributor III
2,004 Views

@MWind2 wrote:

I would not pretend to know if the warning is technically correct fortran, but I find it less than I would expect . 

I would hope that it would check assignments from the RHS with the LHS type and not what it finds on the RHS without context.


@MWind2 , @michaelgreen1 :

You will be surprised with the standard semantics which is that the intrinsic assignment is treated as "var = expr" and the expr - what you call RHS - is essentially evaluated independently of var.

Note you can consider the "canonical" form to work with objects of intrinsic types in Fortran as via defined KINDs, for the case in the original post it will be as follows:

    integer, parameter :: I8 = selected_int_kind( r=10 )
    integer(kind=I8) delta
    delta = 2654435769_i8  !<-- note the RHS
    print *, "delta = ", delta
end

and which the compiler processes without any errors or warnings and helps to generate your expected output:

C:\temp>ifx /standard-semantics /stand /warn:all /free p.f
Intel(R) Fortran Compiler for applications running on Intel(R) 64, Version 2023.1.0 Build 20230320
Copyright (C) 1985-2023 Intel Corporation. All rights reserved.

Microsoft (R) Incremental Linker Version 14.34.31937.0
Copyright (C) Microsoft Corporation.  All rights reserved.

-out:p.exe
-subsystem:console
p.obj

C:\temp>p.exe
 delta =  2654435769

 

0 Kudos
FortranFan
Honored Contributor III
2,003 Views

To add: an integer literal constant without a suffix (e.g., _i8) is treated as default integer which is usually the one with a range of 9 aka a 4-byte word.

0 Kudos
Reply