Integers and standard
  Home FAQ Contact Sign in
comp.lang.fortran only
 
Advanced search
POPULAR GROUPS

more...

comp.lang.fortran Profile…
 Up
Integers and standard         


Author: Alfredo Buttari
Date: Jul 28, 2008 11:15

Hi all,
I have a quick question. Is the following piece legal according to
fortran 77 and/or 90/95 standard?

integer i
data i/z'80000000'/

As far as my understanding goes, it is not but many compilers (intel,
xlf, gfortran 4.2) don't complain about it while others do (g77 gives
a warning, gfortran 4.3 an error).

The problem is that I need to declare this value in a Fortran
interface for a C package that uses the value internally (and, as you
know, this is a legal value in C). Do you know any way to work around
this?
Thanks a lot

Alfredo
78 Comments
Re: Integers and standard         


Author: Steven G. Kargl
Date: Jul 28, 2008 11:31

In article k30g2000hse.googlegroups.com>,
Alfredo Buttari gmail.com> writes:
> Hi all,
> I have a quick question. Is the following piece legal according to
> fortran 77 and/or 90/95 standard?
>
> integer i
> data i/z'80000000'/
>
> As far as my understanding goes, it is not but many compilers (intel,
> xlf, gfortran 4.2) don't complain about it while others do (g77 gives
> a warning, gfortran 4.3 an error).
>
> The problem is that I need to declare this value in a Fortran
> interface for a C package that uses the value internally (and, as you
> know, this is a legal value in C). Do you know any way to work around
> this?
Show full article (0.88Kb)
no comments
Re: Integers and standard         


Author: nospam
Date: Jul 28, 2008 11:45

Alfredo Buttari gmail.com> wrote:
> Hi all,
> I have a quick question. Is the following piece legal according to
> fortran 77 and/or 90/95 standard?
>
> integer i
> data i/z'80000000'/
>
> As far as my understanding goes, it is not

I'll assume that you are talking about 32-bit integers. The standard, of
course, doesn't specify that. If default integer happens, for example,
to be 64 bits, then there is nothing at all wrong with this (in f90; f77
doesn't have hex literals), but I doubt that's what you mean.
Show full article (2.06Kb)
no comments
Re: Integers and standard         


Author: dpb
Date: Jul 28, 2008 11:44

Alfredo Buttari wrote:
> Hi all,
> I have a quick question. Is the following piece legal according to
> fortran 77 and/or 90/95 standard?
>
> integer i
> data i/z'80000000'/
>
...

Standard as of F90.

Would, therefore, be an extension F77-compliant compilers.

--
no comments
Re: Integers and standard         


Author: dpb
Date: Jul 28, 2008 11:48

dpb wrote:
> Alfredo Buttari wrote:
>> Hi all,
>> I have a quick question. Is the following piece legal according to
>> fortran 77 and/or 90/95 standard?
>>
>> integer i
>> data i/z'80000000'/
>>
> ...
>
> Standard as of F90.
>
> Would, therefore, be an extension F77-compliant compilers.

Except, of course, for the problem of overflow into a default (presumed
32-bit) integer.

The result owing to that will be compiler/machine dependent I think.

--
no comments
Re: Integers and standard         


Author: glen herrmannsfeldt
Date: Jul 28, 2008 13:07

dpb wrote:
> Alfredo Buttari wrote:
>> I have a quick question. Is the following piece legal according to
>> fortran 77 and/or 90/95 standard?
>> integer i
>> data i/z'80000000'/
> Standard as of F90.
> Would, therefore, be an extension F77-compliant compilers.

I thought F77 didn't have BOZ constant yet, so it wouldn't
be standard F77.

I believe DATA statements are one of the few places in the
Fortran 77 (and Fortran 66) standard where 'signed integer
constant' is used. Expressions weren't allowed in DATA
statements, so the application of unary negation to a positive
constant, as happens in ordinary expressions, won't work for
DATA statements.
Show full article (1.24Kb)
no comments
Re: Integers and standard         


Author: Alfredo Buttari
Date: Jul 28, 2008 12:15

On Jul 28, 2:15 pm, Alfredo Buttari gmail.com> wrote:
> Hi all,
> I have a quick question. Is the following piece legal according to
> fortran 77 and/or 90/95 standard?
>
>       integer i
>       data i/z'80000000'/
>
> As far as my understanding goes, it is not but many compilers (intel,
> xlf, gfortran 4.2) don't complain about it while others do (g77 gives
> a warning, gfortran 4.3 an error).
>
> The problem is that I need to declare this value in a Fortran
> interface for a C package that uses the value internally (and, as you
> know, this is a legal value in C). Do you know any way to work around
> this?
> Thanks a lot
>
> Alfredo
Show full article (0.85Kb)
no comments
Re: Integers and standard         


Author: glen herrmannsfeldt
Date: Jul 28, 2008 13:42

Richard Maine wrote:
(snip)
> Assuming 2's complement integers (I think I got the term straight -
> anyway - the kind that essentually all curent machines have), that bit
> pattern would be the largest negative integer. That happens to be
> "problematic" because its absolute value overflows (unless there is also
> a larger integer kind), so you have to be careful not to write
> expressions that might parse "inconveniently".

Fortran 2003, section 4.4.1:

"Any integer value may be represented as a signed-int-literal-constant."

It seems to me that allows, on twos complement machines, for the most
negative integer as a signed-int-literal-constant in those few places
where signed-int-literal-constant is used, DATA statements being
one of those places.

It seems that for Z, though, that means -Z'80000000', and not
the more obvious (to some) Z'80000000'.

-- glen
no comments
Re: Integers and standard         


Author: Steven G. Kargl
Date: Jul 28, 2008 13:04

In article comcast.com>,
glen herrmannsfeldt ugcs.caltech.edu> writes:
> Richard Maine wrote:
> (snip)
>
>> Assuming 2's complement integers (I think I got the term straight -
>> anyway - the kind that essentually all curent machines have), that bit
>> pattern would be the largest negative integer. That happens to be
>> "problematic" because its absolute value overflows (unless there is also
>> a larger integer kind), so you have to be careful not to write
>> expressions that might parse "inconveniently".
>
> Fortran 2003, section 4.4.1:
>
> "Any integer value may be represented as a signed-int-literal-constant."
>
> It seems to me that allows, on twos complement machines, for the most
> negative integer as a signed-int-literal-constant in those few places
> where signed-int-literal-constant is used, DATA statements being
> one of those places. ...
Show full article (1.83Kb)
no comments
Re: Integers and standard         


Author: nospam
Date: Jul 28, 2008 13:27

glen herrmannsfeldt ugcs.caltech.edu> wrote:
> It seems that for Z, though, that means -Z'80000000'

That's not a signed-int-literal-constant. Check the bnf - what the bnf
literally and exactly says rather than what you might think that the
terms ought to mean. In particular, although a hex-constant is an
integer, and it is a literal constant, it is not an
int-literal-constant.

--
Richard Maine | Good judgement comes from experience;
email: last name at domain . net | experience comes from bad judgement.
domain: summertriangle | -- Mark Twain
no comments
1 2 3 4 5 6 7 8