Re: Newbie to gfortran needs a little help

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

 



On 01/14/2013 05:22 PM, Tim Prince wrote:
On 1/14/2013 1:16 PM, Mark Hounschell wrote:
I hope this is the correct list to ask. I'm porting a bunch of old
fortran code and am getting thousands of these warnings I don't
understand. Most all are doing some sort of add or subtract on
integer*2 variables. This is just an example.

      program test
      implicit none

      integer*2 val/10/

      val = val - 1

      write(6,10)val
 10  format('val = ',I2)
      stop
      end


compiled with:

f77 -std=legacy -Wall test.f
test.f:6.12:

      val = val - 1
               1
Warning: Possible change of value in conversion from INTEGER(4) to
INTEGER(2) at (1)

Thanks
Mark

Probably innocuous in the case you show.  Your constant "1" is
integer(4) (probably 32-bit, depending on your platform).  You could
change it to 1_2, or, preferably define a parameter constant for this
purpose, giving it the value 2 for constants to be used in integer(2)
arithmetic.  Use of integer(2) is quite rare in the last 15 years in my
experience.
f77 often refers to use of the obsolete f2c method which translates to
C, or it may be (possibly an alias to) another old Fortran compiler,
such as g77, which hasn't been maintained for several years.  gfortran
is the current Fortran compiler companion to gcc.
Tim


Thanks for the pointer. I am running on standard x86 32 bit hardware running Linux. This code I'm porting is actually well over 15 years old. Back then we used interger*2 when ever we could to save precious space. FYI, my 'f77' above is just a link to gfortran. The original compiler was an f77 though. That does get rid of the warning BTW. But how would you do the same this for a function that returns an integer*4 like INDEX, as follows.

       integer*2 val
       val = INDEX(TXTBUFF, 'SOMETEXT')

Would this be the best way or is there an '_2' method for that also?

       val = TRANSFER(INDEX(BUFF,'EVENT'), val)



I ran across the "TRANSFER" Intrinsic while searching for a way to get rid of what turns out be be an error to gfortran. The old compiler would let you do this without complaining:

       integer*4 val
       val = 'ABCD'
       write(6,20)val
 20   format('val = 0x'Z8,)

The above would put 0x41424344' into val. But when I use the Intrinsic "TRANSFER"

       val = TRANSFER ("ABCD", val)

the contents of val is X'44434241', so I can't really use it in all cases because some of these variables are reflected via reflective memory to other 32 bit computers (big endian) not being touched.


Another question is assigning a value such as X'FF000000' to an integer*4. It thinks X'FF000000' must be an integer*8 and I get the error:

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

This just seems wrong to me but is there a way other than -fno-range-check for this sort of thing?

Thanks and 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