comp.lang.ada
 help / color / mirror / Atom feed
* Re: C++ to Ada95, help please
@ 1995-03-20  8:06 Simon Johnston
  1995-03-21 23:27 ` Kevin F. Quinn
                   ` (2 more replies)
  0 siblings, 3 replies; 16+ messages in thread
From: Simon Johnston @ 1995-03-20  8:06 UTC (permalink / raw)


Hi, thanks everyone for helping with my last query. I have a new C nasty for
you. I am converting some C headers into packages for use with GNAT and 
have come accross the old chestnut:

typedef struct _STRUCT_NAME {.....type struct_STRUCT_NAME is
....................................record
  int item1;..........................item1  : int;
  union {                             :
    int  u_item1;                     :
    long u_item2;                     :
  } u_name;                           :
  int item2;..........................item2  : int;
....................................end record;
} STRUCT_NAME;....................type STRUCT_NAME is new struct_STRUCT_NAME;

this I know is a contrived example but it does show the problem, how do I
describe the C struct on the left as an Ada record on the right. (The code
I have put on the right is lifted from the windows.ads package spec provided
in the GNAT examples directory for Windows NT.

Thanks.


MODULE Sig;
FROM ICL IMPORT StdDisclaimer;
FROM Interests IMPORT Modula2, Modula3, Linux, OS2;

BEGIN
(* ------------------------------------------------------------------------.
|Simon K. Johnston - Development Engineer (C/C++)      |ICL Retail Systems |
|------------------------------------------------------|3/4 Willoughby Road|
|Unix Mail : S.K.Johnston@bra0801.wins.icl.co.uk       |Bracknell, Berks   |
|Telephone : +44 (0)344 476320   Fax: +44 (0)344 476302|United Kingdom     |
|Internal  : 7261 6320    OP Mail: S.K.Johnston@BRA0801|RG12 8TJ           |
`------------------------------------------------------------------------ *)
END Sig.



^ permalink raw reply	[flat|nested] 16+ messages in thread
* C++ to Ada95, help please
@ 1995-03-08  7:54 Simon Johnston
  1995-03-08 13:56 ` Robert A Duff
  1995-03-09 21:23 ` Tucker Taft
  0 siblings, 2 replies; 16+ messages in thread
From: Simon Johnston @ 1995-03-08  7:54 UTC (permalink / raw)


Hi, I am moving over to Ada95 from C++, I did do some Ada a while ago, and I
am fairly confident, but I need some help to move some C++ knowledge onto
Ada95.

First I would like to declare an Opaque type, or in C++ a 'smiley'.  There
are two uses for such a feature. First, where a class' implementation may
change greatly, and I want to really hide this from clients I would declare
a class for the implementation and hide it. C++ allows this as if you only
use a pointer to the opaque type then the compiler knows the size of it and
does not need to know more. The second is where you have some information 
that the client may request, but the client can only use it by passing it 
back to you. I have used this in a text screen class to save and restore the
screen contents, the client cannot manipulate the screen object as they 
cannot know what it is, and as the screen object is platform dependant I can
use a completely different implementation behind the scenes. I include two 
examples below to illustrate.

// Start ->
class ACollectionClass {
public:
  ...
private:
  class Implementation;
  Implementation* hidden;
};

class Screen {
public:
  ...
  class SavedScreen;
  const SavedScreen* save(void);
  void  restore(SavedScreen* image);
};
// <- end.

Now I know from experience I can do this sort of thing in C++, Modula-2 and
Modula-3 but I cannot see how to do it in Ada, even using private types.


Thanks very much.

MODULE Sig;
FROM ICL IMPORT StdDisclaimer;
FROM Interests IMPORT Modula2, Modula3, Linux, OS2;

BEGIN
(* ------------------------------------------------------------------------.
|Simon K. Johnston - Development Engineer (C/C++)      |ICL Retail Systems |
|------------------------------------------------------|3/4 Willoughby Road|
|Unix Mail : S.K.Johnston@bra0801.wins.icl.co.uk       |Bracknell, Berks   |
|Telephone : +44 (0)344 476320   Fax: +44 (0)344 476302|United Kingdom     |
|Internal  : 7261 6320    OP Mail: S.K.Johnston@BRA0801|RG12 8TJ           |
`------------------------------------------------------------------------ *)
END Sig.




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

end of thread, other threads:[~1995-03-27 14:58 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1995-03-20  8:06 C++ to Ada95, help please Simon Johnston
1995-03-21 23:27 ` Kevin F. Quinn
1995-03-22  5:07   ` Vladimir Vukicevic
1995-03-22  1:22 ` Tucker Taft
1995-03-22 11:38   ` Robb Nebbe
1995-03-23 12:28   ` Mike Meier
1995-03-23 18:31     ` Tucker Taft
1995-03-24 21:24     ` Robert Dewar
1995-03-27 14:58       ` Norman H. Cohen
1995-03-23 13:30   ` Robert Dewar
1995-03-23 18:01 ` Stephen A. Leake
1995-03-24  9:07   ` Vladimir Vukicevic
1995-03-25 10:02     ` Keith Thompson
  -- strict thread matches above, loose matches on Subject: below --
1995-03-08  7:54 Simon Johnston
1995-03-08 13:56 ` Robert A Duff
1995-03-09 21:23 ` Tucker Taft

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