comp.lang.ada
 help / color / mirror / Atom feed
* unchecked_conversion of tag; windows binding
@ 1996-04-17  0:00 tmoran
  0 siblings, 0 replies; only message in thread
From: tmoran @ 1996-04-17  0:00 UTC (permalink / raw)


How does one change the tag of a derived type to get a different
view of the bit pattern of the data?
  The question arose in my attempt to move part of an R20 Windows/OS2
binding from Ada 83 to 95.  In Ada 83,
  type WM_CHAR_param is record
    char:character;
    keypress_info:keypress_infos;
  end record;
  ...
  type parameters(Message: UINT) is record
    case Message is
      when WM_CHAR              =>
        WM_CHAR_param      : WM_CHAR_params;
      when WM_COMMAND           =>
        WM_COMMAND_param   : WM_COMMAND_params;
  ...
allows a call to
  procedure Some_Wndproc(param:in parameters) is
  ...
    case param.message is
      when WM_CHAR => ...
        if param.char = 'X' ...
      when others  =>
        null;
    end case;
so Some_Wndproc code needn't use error prone and non-portable
LOWORD(WParam) type constructs but can simply refer to param.char
or whatever.  This approach does have the disadvantage that any
new message type introduced by MS or anyone else requires adding
to the 'type parameters ...' declaration, which introduces a delay
if it's a public standard and requires mucho recompilation of
dependent units.  The obvious Ada 95 approach is
  type WMs is tagged record
    Message:UINT;
  end record;

  type WM_CHAR_params is new WMs with record
    char:character;
    keypress_info:keypress_infos;
  end record;
etc.  (A minor annoyance is that "case param'tag" is apparently
illegal, so if-elsif sequences are needed.)  In the variant
record version it's easy to use record rep clauses to lay out
the Message discriminant and WParam and LParam and the various
WM_xxx_params and do an unchecked_conversion to transfer the
WndProc parameters into the Some_Wndproc(parameter).  But how
does one accomplish this with the Ada 95 tagged record approach?




^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1996-04-17  0:00 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-04-17  0:00 unchecked_conversion of tag; windows binding tmoran

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