comp.lang.ada
 help / color / mirror / Atom feed
From: Keith Thompson <kst-u@mib.org>
Subject: Re: Enumeration representation clause surprise.
Date: Fri, 13 Jun 2008 10:52:43 -0700
Date: 2008-06-13T10:52:43-07:00	[thread overview]
Message-ID: <lnwsktfcic.fsf@nuthaus.mib.org> (raw)
In-Reply-To: 1c847838-26d7-4517-a010-1851aa12351a@m3g2000hsc.googlegroups.com

Mike Silva <snarflemike@yahoo.com> writes:
> On Jun 13, 3:21�am, Keith Thompson <ks...@mib.org> wrote:
>> Mike Silva <snarflem...@yahoo.com> writes:
>> > On Jun 12, 2:41�pm, Markus Sch�pflin <nos...@nospam.org> wrote:
>> >> Mike Silva schrieb:
>> [...]
>> >> > Are you saying now that there's no problem after all?
>>
>> >> Not at all. The memory layout of the variables is not what I expect it
>> >> to be, because the compiler silently biased those values. The compiler
>> >> is perfectly aware of this, as it makes up for the biasing when
>> >> explicitly querying the value, but this doesn't help at all because I'm
>> >> interested in the exact bitwise representation.
>>
>> >> Admittedly, there is an inconsistency in what I'm asking the compiler to
>> >> do, but that's the whole point: I do not want this inconsistency to be
>> >> silently 'fixed' by the compiler, I want to get noted about my error to
>> >> get a chance and fix it myself.
>>
>> > I wonder then if this is an error at all. �IANALL, but if the program
>> > makes available your specified values when queried with the proper
>> > mechanism (in this case, unchecked conversion), then I don't see what
>> > difference it makes how it stores the representations in raw memory.
>>
>> > I'd welcome other comments on the validity or non-validity of this
>> > view.
>>
>> If it doesn't make any difference how the representations are stored
>> in raw memory, then you wouldn't use a representation clause; you'd
>> let the compiler make any decisions about representation, subject to
>> the constraint that the code has to produce the right answers.
>>
>> But if you *do* provide a representation clause, then the
>> representation clearly *does* matter. �And if the compiler can't
>> satisfy the requested representation (e.g., because two representation
>> clauses contradict each other), then the compiler should reject the
>> compilation unit.
>> 
> So that's why I'm wondering why compiler writers ever introduced
> biased representations in the first place.  I can't believe that the
> problem with this approach has only been noticed in 2008.  Aren't
> biased representations fundamentally incompatible with "the
> representation clearly *does* matter"?

Oh, I see what you mean (I was missing your point).

Hmm.

Using a biased representation when the user has specified the
exact representation via an enumeration representation clause seems
clearly wrong.

My thought was that a biased representation is perfectly ok if the
user didn't specify the representation.  The point I missed is that
a biased representation is going to be used only if the user asked
for something to be smaller than it would ordinarily be.

So the question is, if I have something with range 100..101, and
I use a record representation clause to request that it be stored
in 1 bit, is it ok to use a biased representation, mapping 100 to
0 and 101 to 1?

I think I'd still argue that it's ok, since I only specified one
particular aspect of the representation, namely the number of bits.
I didn't specify that 100 be represented as the bit sequence 1100100,
and 101 as the bit sequence 1100101 (partly because there's no
mechanism to specify that).  If the compiler is able to generate code
that gets the right answers *and* that satisfies those aspects of
the representation that I specified, that's (at least arguably) ok.

But I'd still say that a warning is appropriate, so that if I
really do want an unbiased representation I can change the clause
to allocate at least 7 bits.

Using a biased representation in the presence of pragma Pack is
perhaps another question.  In that case, I've only specified minimal
size, and deliberately refrained from specifying the details.
But always warning about biased representations isn't a bad idea
anyway.

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
Nokia
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"



  parent reply	other threads:[~2008-06-13 17:52 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-11 11:38 Enumeration representation clause surprise Markus Schoepflin
2008-06-11 12:30 ` christoph.grein
2008-06-11 12:56   ` Markus Schoepflin
2008-06-11 13:08     ` christoph.grein
2008-06-11 13:28     ` Samuel Tardieu
2008-06-11 13:48       ` Markus Schoepflin
2008-06-11 13:56         ` Samuel Tardieu
2008-06-11 14:58       ` Adam Beneschan
2008-06-11 15:23         ` Markus Schoepflin
2008-06-12  2:37           ` Randy Brukardt
2008-06-12  2:37           ` Randy Brukardt
2008-06-11 15:56         ` Samuel Tardieu
2008-06-11 19:10           ` Adam Beneschan
2008-06-11 19:59             ` Niklas Holsti
2008-06-12  1:16               ` tmoran
2008-06-12  8:27                 ` christoph.grein
2008-06-12  8:45               ` Markus Schoepflin
2008-06-12 16:43                 ` Mike Silva
2008-06-12 18:41                   ` Markus Schöpflin
2008-06-12 20:10                     ` Mike Silva
2008-06-12 20:52                       ` Simon Wright
2008-06-12 23:36                         ` Mike Silva
2008-06-13  5:49                           ` Simon Wright
2008-06-13  7:21                       ` Keith Thompson
2008-06-13 13:31                         ` Mike Silva
2008-06-13 14:45                           ` Markus Schoepflin
2008-06-13 17:52                           ` Keith Thompson [this message]
2008-06-13  9:14                       ` Jean-Pierre Rosen
2008-06-12 19:05 ` richtmyer
2008-06-12 21:26   ` Samuel Tardieu
2008-06-12 22:42     ` Adam Beneschan
2008-06-13  7:11       ` Samuel Tardieu
2008-06-13  8:27       ` christoph.grein
2008-06-13 16:21         ` Adam Beneschan
2008-06-15 19:33           ` Robert A Duff
2008-06-16 14:50             ` Adam Beneschan
2008-06-16 19:18               ` Robert A Duff
2008-06-17  6:03               ` christoph.grein
2008-06-17  7:22                 ` christoph.grein
2008-06-13  8:24     ` Peter Hermann
2008-06-13 14:47       ` Samuel Tardieu
2008-06-14 11:48         ` John B. Matthews
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox