- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@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.
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page