comp.lang.ada
 help / color / mirror / Atom feed
* RE: Zero_Fill pragma, other proposition
@ 2004-07-21 16:50 Lionel.DRAGHI
  0 siblings, 0 replies; 6+ messages in thread
From: Lionel.DRAGHI @ 2004-07-21 16:50 UTC (permalink / raw)
  To: comp.lang.ada

| -----Message d'origine-----
| De: Nick Roberts [mailto:nick.roberts@acm.org]
..
|     for Message use record
|        Id    at 0 range 0 .. 7;
|        all 0 at 0 range 8 .. 15;
|        Data  at 0 range 16 .. 65;
|     end record;
 
Its a better syntax, as it doens't require a field name, but the "all" does
not fit well with random value.

So why not directly a numeric literal?
 
for Message use record
   Id           at 0 range 0 .. 7;
   2#1011_1010# at 0 range 8 .. 15;
   Data         at 0 range 16 .. 65;
end record;

That's pretty clear, isn't it?

-- 
Lionel Draghi



^ permalink raw reply	[flat|nested] 6+ messages in thread
* RE: Zero_Fill pragma, other proposition
@ 2004-07-21 13:17 Lionel.DRAGHI
  0 siblings, 0 replies; 6+ messages in thread
From: Lionel.DRAGHI @ 2004-07-21 13:17 UTC (permalink / raw)
  To: comp.lang.ada

| -----Message d'origine-----
...
| > type Message is record
| >    Id   : Message_Id;
| >    Data : Byte_Stream;
| > end record;
| >
| > for Message use record
| >    Id    at 0 range 0 .. 7;
| >    Spare at 0 range 8 .. 15 := 0; --> ADDED
| >    Data  at 0 range 16 .. 65;
| > end record;
| >
...........................................................
| package P is
|    type Message is record
|       Id   : Message_ID;
|       Data : Byte_Stream;
|    end record;
| 
|    -- Primitive operations of Message go here
| private
|    type Representation is record
|       Id    : Message_ID;
|       Spare : Eight_Bits;
|       Data  : Byte_Stream;
|    end record;
| 
|    for Representation use record
|       Id    at 0 range 0 .. 7;
|       Spare at 0 range 8 .. 15;
|       Data  at 0 range 16 .. 65;
|    end record;
|    
|    function To_Rep (M : in Message) return Representation;
|    function To_Message (R : in Representation) return Message;
| end P;
| 
| 
| package body P is
|    function To_Rep (M : in Message) return Representation is
|    begin
|       return (Id => M.Id, Spare => 0, Data => R.Data);
|    end To_Rep;
| 
|    function To_Message (R : in Representation) return Message is
|    begin
|       return (Id => R.Id, Data => R.Data);
|    end To_Message;
| 
|    -- Primitive operations of Message convert to 
| Representation whenever
|    -- interfacing to hardware
| end P;
| 
| I realise that your proposal reduces the amount of work required to
| achieve this, but the current language does allow you to do what you
| want.
Yes, and the problem is not so common.
 
On the other hand:
- even on this small example, there is a big difference in required work
(about 1 line vs 20), and a body is required, 
- it betters representation details encapsulation,
- it's not a big deal to implement... OK, I don't know about this, but I
bet!

-- 
Lionel Draghi



^ permalink raw reply	[flat|nested] 6+ messages in thread
* RE: Zero_Fill pragma, other proposition
@ 2004-07-21  9:20 Lionel.DRAGHI
  2004-07-21 10:09 ` Ludovic Brenta
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Lionel.DRAGHI @ 2004-07-21  9:20 UTC (permalink / raw)
  To: comp.lang.ada



| -----Message d'origine-----
| De: Jean-Pierre Rosen [mailto:rosen@adalog.fr]
...
| OTOH, I suspect that very few types would need
| that pragma (as you describe, a couple of types very strongly 
| connected to hardware), so writing more fields is not really a
| problem.
In our case, it's a common problem : we have lots of messages with spare
fields, and setting them to 0 for out going messages is a requirement.
(On the other hand, even without this requirement, it would ease regression
testing.
Simple regression test tools based on diff raise false alarm because spare
fields may be whatever on each run).

So, our current policy is to explicitly state each spare. I don't feel
confortable with this because the low level representation emerge in the
definition.
I don't want users to access the spare fields.
I don't event want users to see the spare fields.

What could be a good deal is to allows spare fields to appear in the
representation clause.

Kind of :

type Message is record
   Id   : Message_Id;
   Data : Byte_Stream;
end record;

for Message use record
   Id    at 0 range 0 .. 7;
   Spare at 0 range 8 .. 15 := 0; --> ADDED
   Data  at 0 range 16 .. 65;
end record;

This way, representation stuff don't emerge in the "user's" view, but spares
are explicit in the "coder's" view.

-- 
Lionel Draghi



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2004-07-21 19:50 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-07-21 16:50 Zero_Fill pragma, other proposition Lionel.DRAGHI
  -- strict thread matches above, loose matches on Subject: below --
2004-07-21 13:17 Lionel.DRAGHI
2004-07-21  9:20 Lionel.DRAGHI
2004-07-21 10:09 ` Ludovic Brenta
2004-07-21 15:07 ` Nick Roberts
2004-07-21 19:50 ` Wes Groleau

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