Catherine Moroney writes:
> How does Fortran handle signed vs. unsigned integers, given that there's
> only a single integer datatype?
Where did you get the idea that there is ncessarily only a single
integer data type? Well, yes its all one type, but there are multiple
integer kinds. Unless you are talking about Fortran 77. But this
doesn't really affect the answer to your actual question; its just a
side note.
You are correct to note, however, that there is no concept of an
unsigned integer in Fortran.
> If you assign a value > 127 to an integer*1 variable...
Integer*1 is not a Fortran type. It is a vendor extension. As with
any extension, there is no requirement on exactly what it has to do.
It does whatever the vandor makes it do, and that may vary from vendor
to vendor.
But independent of that....
> does Fortran then assume that it's going to be an
> unsigned int and treat it accordingly? And, if you assign a negative number,
> does the compiler then figure out to treat it as a signed int?
No to all of this. There is no "magic". If you try to assign a
variable with a value that is outside of the range that is allowed for
the variable, then the program is illegal. There is no guarantee
what will happen with illegal code. In general, different compilers
will do different things.
> And, is the following behaviour a compiler bug?
[elided]
No. Its just illegal code. You are using integer* syntax that is
nonstandard, so the compiler can do whatever it wants. Even
if you change to a standard syntax, the compiler can do whatever it
wants if you assign a value larger than the type supports. Behavior
can and does vary among compilers in such areas.
--
Richard Maine
[log in to unmask]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|