Re: Integers and standard
- From: nospam@xxxxxxxxxxxxx (Richard Maine)
- Date: Mon, 28 Jul 2008 17:33:43 -0700
Gary Scott <garylscott@xxxxxxxxxxxxx> wrote:
I think the fundamental issue is using integer to represent multiple
data types, bit string being the other I commonly use. In nearly all of
my applications, one or more integers represent a flag-based control
register for some I/O device. So, the 1st bit isn't a sign bit, it
means "put I/O device in mode x".
I'd agree with you here - that this is a fundamental part of the
problem. Unfortunately, we don't have suitable bit type in Fortran.
(And I don't recall whether the proposed new type made it into the f2008
draft either. I think it ended up getting pulled, though I'm not sure
about that. At a quick glance, I don't see it. In my personal view, a
flaw of at least some versions of the proposal was that they perpetuated
this dual-nature problem by trying to define arithmetic operations on
the bit type as though it were an unsigned integer. That might have
gotten fixed in subsequent drafts. Anyway...)
Lacking a real bit type....um, unfortunate wording there - perhaps I
should say something more like "a proper bit type"... I agree that
integer is the closest substitute.
But I think it important to keep in mind that it is a substitute instead
of the real....um, make that "proper"... thing. When you are using types
for other than their defined purpose, I think it is especially important
to keep the distinction in mind.
Dan's "get over it" wording is perhaps a little harsher than I'd use
(well, I might use it in a draft, but I'd probably edit it out before
posting :-)). But I think it says the same thing. Fortran integers
aren't bit patterns. Insert Dan's harsh words here. They are close
enough that you can make them serve the purpose, but if you forget,
you'll get in trouble.
Interestingly, the f2008 draft might be of some help here. That draft
recategorizes the hex (and octal, and binary) literal constants.
In f90/f95/f2003, they were categorized as integers. But they could be
used in so few places, that the categorization perhaps got in the way
more than it helped. It isn't as though you could ever do numeric
operations on them, or anything else where their type actually mattered.
(For example, as noted before in reply to Glen, you can't write
-Z'...').
But in the f2008 draft, these forms are no longer categorized as
integers. Thus most of the above comments about abuse of integers become
moot (along with the harsh words). They *ARE* (well, perhaps I should
use some kind of future conditional tense, as this is a draft of a
future standard instead of the published version of the present one)
defined as bit patterns. To quote the draft "Such a constant has no
type". But again, they are allowed in so few places that you don't need
the general type mechanism. Each place where they can be used already
had a special-case explanation of what they meant in that case.
The extensions that allow you to use these forms in other contexts are a
different matter. Anyone who has something like
real x
x = 42 + z'....'
is just tempting fate as to whether any particular compiler will accept
it at all, or, if accepted, what it will mean. For that, I think I would
go with the harsh words. It's a bad idea that will come to no good end;
don't do it and don't expect the standard or compilers to come to your
aid if you do.
--
Richard Maine | Good judgement comes from experience;
email: last name at domain . net | experience comes from bad judgement.
domain: summertriangle | -- Mark Twain
.
- Follow-Ups:
- Re: Integers and standard
- From: glen herrmannsfeldt
- Re: Integers and standard
- References:
- Integers and standard
- From: Alfredo Buttari
- Re: Integers and standard
- From: Richard Maine
- Re: Integers and standard
- From: glen herrmannsfeldt
- Re: Integers and standard
- From: Steven G. Kargl
- Re: Integers and standard
- From: glen herrmannsfeldt
- Re: Integers and standard
- From: Steven G. Kargl
- Re: Integers and standard
- From: glen herrmannsfeldt
- Re: Integers and standard
- From: Dan Nagle
- Re: Integers and standard
- From: glen herrmannsfeldt
- Re: Integers and standard
- From: Gary Scott
- Integers and standard
- Prev by Date: Re: Integers and standard
- Next by Date: Re: Integers and standard
- Previous by thread: Re: Integers and standard
- Next by thread: Re: Integers and standard
- Index(es):