From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,e6a49204d9da83ed,start X-Google-Attributes: gid103376,public From: tmoran@bix.com Subject: unchecked_conversion of tag; windows binding Date: 1996/04/17 Message-ID: <4l3o1a$cvc@news1.delphi.com>#1/1 X-Deja-AN: 148040051 organization: Delphi Internet Services Corporation newsgroups: comp.lang.ada Date: 1996-04-17T00:00:00+00:00 List-Id: 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?