Re: How to do this in gfortran

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 01/28/2013 10:38 AM, Mark Hounschell wrote:
On 01/28/2013 10:14 AM, Tim Prince wrote:
On 01/28/2013 09:02 AM, Mark Hounschell wrote:
I am porting some very old code. I have many things like below in this
code


       program test
       implicit none

       integer*1 ivalx1
       integer*2 ivalx2
       integer*4 ivalx4

       parameter (ivalx1 = x'80')
       parameter (ivalx2 = x'8000')
       parameter (ivalx4 = x'80000000')

The compiler fails with:

f77 test.f
test.f:8.26:

       parameter (ivalx1 = x'80')
                          1
Error: Arithmetic overflow converting INTEGER(8) to INTEGER(1) at (1).
This check can be disabled with the option -fno-range-check
test.f:9.26:

       parameter (ivalx2 = x'8000')
                          1
Error: Arithmetic overflow converting INTEGER(8) to INTEGER(2) at (1).
This check can be disabled with the option -fno-range-check
test.f:10.26:

       parameter (ivalx4 = x'80000000')
                          1
Error: Arithmetic overflow converting INTEGER(8) to INTEGER(4) at (1).
This check can be disabled with the option -fno-range-check

I don't want to use the -fno-range-check option because I want to know
about the real ones. I don't understand why gfortran has issues with
this. They are certainly valid values for the the types specified. I
have been, just setting the values in the code section using the
'transfer' instrinsic but now I'm finding these in include files and I
would have to change every source file that used the particular
include file. I'm sure there is an easy solution. Could someone
enlighten me please.

Thanks and Regards
Mark
Perhaps you could arrange to make the constants come out as x'80'_1,
x'8000'_2, x'80000000'_4, or
-1_1, -1_2, -1_4.  The values you set aren't valid positive integer
values in the smaller type.


Why must it be a valid "positive integer"? How/why does the compiler
even know/care whether I am going to use this data for an arithmetic
operation or not. Even if I was, it should be up to me to be able to set
the sign bit myself. x'80' is a valid negative integer*1 etc...


So, it will let me use  negative decimal numbers but negative hex numbers.

for the case

        integer*2 ivalx2
        parameter (ivalx2 = x'8000')    ! == -32768

if I use the decimal equivalent

        integer*2 ivalx2
        parameter (ivalx2 = -32768)     ! == x'8000'

It works just fine. The other integer sizes are the same. This is clearly a BUG to me. Can someone convince me it is not?

Regards
mark


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux