Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Are BOZ constants in PARAMETER statements allowed by the standard?

365 views
Skip to first unread message

FortranFan

unread,
Aug 6, 2014, 11:05:02 AM8/6/14
to
Is an expression such as

INTEGER(KIND=4), PARAMETER :: Foo = Z"5EB52"

allowed by the current Fortran standard?

gfortran 4.9 throws the following error during compilation with the following options "-g -Wall -std=f2008":

INTEGER(KIND=4), PARAMETER :: Foo = Z"5EB52"
1
Error: GNU Extension: BOZ literal at (1) outside a DATA statement and outside INT/REAL/DBLE/CMPLX

Thanks,

Arjen Markus

unread,
Aug 6, 2014, 11:41:24 AM8/6/14
to
Op woensdag 6 augustus 2014 17:05:02 UTC+2 schreef FortranFan:
Try:

INTEGER(KIND=4), PARAMETER :: Foo = int(Z"5EB52")

BOZ constants are allowed in these intrinsics.

Regards,

Arjen

Clive Page

unread,
Aug 6, 2014, 11:44:54 AM8/6/14
to
On 06/08/2014 16:05, FortranFan wrote:
> Is an expression such as
>
> INTEGER(KIND=4), PARAMETER :: Foo = Z"5EB52"
>
> allowed by the current Fortran standard?

The constant needs to be put as an argument of INT (or another type
conversion function) e.g.

INTEGER(KIND=4), PARAMETER :: Foo = INT(Z"5EB52")

It's really your own fault for using these new-fangled PARAMETER
statements; if you'd stuck to good old DATA you wouldn't have this
problem, as they are still allowed there. :-)

> Error: GNU Extension: BOZ literal at (1) outside a DATA statement and outside INT/REAL/DBLE/CMPLX

The error message was telling you something useful actually. I'm
impressed with the gnu compiler.


--
Clive Page

JWM

unread,
Aug 6, 2014, 4:44:11 PM8/6/14
to
If you're going for things like C interoperability, the intrinsic is
actually quite convenient:

integer(C_INT) :: Foo = INT(Z"5EB52", C_INT)

--
John.


FortranFan

unread,
Aug 6, 2014, 4:51:13 PM8/6/14
to

Thanks Arjen and Clive.

>
> INTEGER(KIND=4), PARAMETER :: Foo = INT(Z"5EB52")
>
>
>
> It's really your own fault for using these new-fangled PARAMETER
>
> statements; if you'd stuck to good old DATA you wouldn't have this
>
> problem, as they are still allowed there. :-)
>
>

Oh, I totally agree with the part about my own fault - I hear that all the time, especially at home!! :-)

But I'm so glad the compilers are inching ever so closer to the Fortran 2008 standard and I can put behind DATA statements! I'd rather get tripped several times by some intricacies of the latest standard than have to use DATA or a whole bunch of other constructs from FORTRAN 77 and earlier standards! And it was a shame when many coders felt compelled to use DATA, an initialization construct, for program invariants for which PARAMETER is best suited.

>
> > Error: GNU Extension: BOZ literal at (1) outside a DATA statement and outside INT/REAL/DBLE/CMPLX
>
>
>
> The error message was telling you something useful actually. I'm
>
> impressed with the gnu compiler.
>
>

I agree, so I now always run my code through gfortran for further checks.

Gary Scott

unread,
Aug 6, 2014, 7:49:30 PM8/6/14
to
On 8/6/2014 10:44 AM, Clive Page wrote:
> On 06/08/2014 16:05, FortranFan wrote:
>> Is an expression such as
>>
>> INTEGER(KIND=4), PARAMETER :: Foo = Z"5EB52"
>>
>> allowed by the current Fortran standard?
>
> The constant needs to be put as an argument of INT (or another type
> conversion function) e.g.
>
> INTEGER(KIND=4), PARAMETER :: Foo = INT(Z"5EB52")

i wanted to do:

call foo(Z"52"_1) to indicate a kind type of 1 yesterday...seems obvious :(

TO in

Ian Harvey

unread,
Aug 6, 2014, 8:12:08 PM8/6/14
to
On 2014-08-07 9:49 AM, Gary Scott wrote:
...
> i wanted to do:
>
> call foo(Z"52"_1) to indicate a kind type of 1 yesterday...seems obvious :(

Did you want a REAL or an INTEGER?


robin....@gmail.com

unread,
Aug 6, 2014, 8:58:59 PM8/6/14
to
On Thursday, August 7, 2014 9:49:30 AM UTC+10, Gary Scott wrote:
> On 8/6/2014 10:44 AM, Clive Page wrote:
>
> > On 06/08/2014 16:05, FortranFan wrote:
>
> >> Is an expression such as
>
> >>
>
> >> INTEGER(KIND=4), PARAMETER :: Foo = Z"5EB52"
>
> >>
>
> >> allowed by the current Fortran standard?
>
> >
>
> > The constant needs to be put as an argument of INT (or another type
>
> > conversion function) e.g.
>
> >
>
> > INTEGER(KIND=4), PARAMETER :: Foo = INT(Z"5EB52")
>
>
>
> i wanted to do:
>
>
>
> call foo(Z"52"_1) to indicate a kind type of 1 yesterday...seems obvious :(

A kind type of 1 is not portable.

Steve Kargl

unread,
Aug 6, 2014, 9:28:05 PM8/6/14
to
BOZ isn't portable either.

--
steve

Steve Kargl

unread,
Aug 6, 2014, 9:33:45 PM8/6/14
to
On 8/6/2014 4:49 PM, Gary Scott wrote:

> i wanted to do:
>
> call foo(Z"52"_1) to indicate a kind type of 1 yesterday...seems obvious :(
>


It's not clear if you wanted to do this with gfortran or something
other compiler. In any event, I fixed this nonstandard in gfortran
a long time ago. From ChangeLog-2005


2005-02-27 Steven G. Kargl <ka...@gcc.gnu.org>

PR fortran/20058
* trans-types.c (gfc_max_integer_kind): Declare
(gfc_init_kinds): Initialize it.
* gfortran.h (gfc_max_integer_kind): extern it.
* primary.c (match_boz_constant): Use it; remove
gfortran extension of kind suffixes on BOZ literal
constants

--
steve


Gary Scott

unread,
Aug 6, 2014, 9:53:17 PM8/6/14
to
i wanted that bit pattern stuffed into the receiving entity. in this
case, it was integer of 1 byte.

Gary Scott

unread,
Aug 6, 2014, 9:54:01 PM8/6/14
to
I know that, that's why my real code had a parameter/constant called "b8".

Richard Maine

unread,
Aug 6, 2014, 10:54:59 PM8/6/14
to
But the compiler doesn't know that, unless perhaps foo has an explicit
interface. And even with an explicit interface, having the compiler
deduce the type of the actual argument would violate the almost
universal principle of expression evaluation not being influenced by
context. The exceptions to that principle are, well, exceptional. It
would also cause circularity problems if foo were generic - deducing the
type of the actual based on the type of the dummy, but having the
specific procedure (and thus the type of the dummy) depend on the type
of the actual.

Of course, if type parameters for different types were guaranteed to be
disjoint, which I'd have liked, things might work better, but I'm afraid
it's a bit late for that.

--
Richard Maine
email: last name at domain . net
domain: summer-triangle

robin....@gmail.com

unread,
Aug 6, 2014, 11:33:30 PM8/6/14
to
On Thursday, August 7, 2014 11:28:05 AM UTC+10, Steve Kargl wrote:
> On 8/6/2014 5:58 PM, r.no...@gmail.com wrote:
>
> > On Thursday, August 7, 2014 9:49:30 AM UTC+10, Gary Scott wrote:
>
> >>
>
> >> i wanted to do:
>
> >> call foo(Z"52"_1) to indicate a kind type of 1 yesterday...seems obvious :(

> > A kind type of 1 is not portable.
>
> BOZ isn't portable either.

That's already been established.

Gary Scott

unread,
Aug 7, 2014, 8:53:50 AM8/7/14
to
In this case, I was attempting to be helpful and tell the compiler that
the receiving type was integer(1) type. In any case, was copying C code
which uses hex numbers to pass opcodes to an ADC board. I thought I
would improve it by telling the compiler the proper kind of the input
argument.

Gordon Sande

unread,
Aug 7, 2014, 9:52:52 AM8/7/14
to
INT takes a kind so it would be a bit longer and absolutely clear to use

int ( z"52", kind = 1 )

so that the thing would certainly be what was intendeded.

robin....@gmail.com

unread,
Aug 7, 2014, 9:34:31 PM8/7/14
to
On Thursday, August 7, 2014 11:52:52 PM UTC+10, Gordon Sande wrote:
> On 2014-08-07 12:53:50 +0000, Gary Scott said:
>
>
>
> > On 8/6/2014 9:54 PM, Richard Maine wrote:
>
Except that it's not portable.

glen herrmannsfeldt

unread,
Aug 7, 2014, 10:15:03 PM8/7/14
to
robin....@gmail.com wrote:
> On Thursday, August 7, 2014 11:52:52 PM UTC+10, Gordon Sande wrote:
>> On 2014-08-07 12:53:50 +0000, Gary Scott said:

(snip)
>> > the receiving type was integer(1) type. In any case, was copying C
>> > code which uses hex numbers to pass opcodes to an ADC board. I thought
>> > I would improve it by telling the compiler the proper kind of the input
>> > argument.

>> INT takes a kind so it would be a bit longer and absolutely clear to use
>> int ( z"52", kind = 1 )
>> so that the thing would certainly be what was intendeded.

> Except that it's not portable.

Neither is writing to ADC boards, but the OP seems to be doing that.

Why not mention that?

-- glen

Gary Scott

unread,
Aug 8, 2014, 9:08:25 AM8/8/14
to
:) sure, but looks really kludgy...

Gary Scott

unread,
Aug 8, 2014, 9:09:48 AM8/8/14
to
It seems that some people want to prevent the use of Fortran for
"system" programming tasks that it works just fine for :(

Dan Nagle

unread,
Aug 8, 2014, 10:20:04 AM8/8/14
to
Hi,
If you really want to be portable,

use, intrinsic :: iso_fortran_env, only: int8
. . .
int( z'abc', kind= int8)

--
Cheers!

Dan Nagle

0 new messages