comp.lang.ada
 help / color / mirror / Atom feed
From: spiegel@bruessel.informatik.uni-stuttgart.de (Andre Spiegel)
Subject: Flags in Ada?
Date: Tue, 25 Oct 1994 10:36:57 GMT
Date: 1994-10-25T10:36:57+00:00	[thread overview]
Message-ID: <SPIEGEL.94Oct25113657@berlin.bruessel.informatik.uni-stuttgart.de> (raw)

I am trying to use UNIX system calls from Ada, which has been working
fine so far, i.e. the `translation' into Ada looks rather neat and
secure (enumeration types with representation clauses for C #define'd
constants, etc.), but how would I go about representing *flags* --
i.e. words, in which the individual bits have names, and can be set,
cleared, or'ed, xor'ed, and the like?

I seem to recall that all of this is realized very comfortably in Ada
9X, but how can I do it in Ada 83?

Another question: UNIX returns a pointer to some data structure, which
I want to read and possibly modify from within Ada. What would be the
adequate way to do this? Off the cuff, I can think of two
possibilities:

  (1) declare the operating system routine to be returning an access
      value, pointing to an Ada record, which resembles the C
      structure.

	type Data is record
                       ...
	             end record;

	type Data_Access is access Data;

        function OS_Routine (...) return Data_Access;

      Disadvantage: As far as I know, access types do not necessarily 
      have to be implemented as pointers. I have read (recently in
      this group), that GNAT, for example, doesn't always do that.
      Also, the Sparc Alsys compiler (which I'm using) seems to use
      the numeric address *one* to indicate a null access value...

  (2) declare the operating system routine to be returning
      System.Address, and use an address clause to interpret the
      memory area pointed to as the corresponding structure.

        function OS_Routine (...) return System.Address;

        Data_Pointer : System.Address;

	...

        Data_Pointer := OS_Routine (...);

        -- check for null address here, using Unchecked_Conversion
        -- to convert Data_Pointer to Integer?

	declare
          Result : Data;
	  for Result use at Data_Pointer;
        begin
          -- process Result...
        end;
 
      Questions: Is this acceptable? Why does RM83 13.5(8) forbid to
      use address clauses to achieve overlays, then? How do compilers 
      usually implement this -- does the declare statement force 
      data allocation on the stack, or is it optimized away, yielding
      simply a bypass of the type checking system, just like a `call'
      to Unchecked_Conversion should simply translate into _nothing_,
      if I'm not all wrong?

In either of these possibilities, what if `Data' is a record with
variants (forced to the right representation with a rep clause)? Might
Ada get into trouble when interpreting it, or even refuse to work with
a record value it has not assigned and checked itself?

Again, I'm primarily interested in the `83 solutions, but would also
like to learn how everything will be much simpler and more 
straightforward in `9X :-). 

BTW, I'm sure all of this has already been asked and discussed at
length. Forgive me if this is just an FAQ.

Regards,

--
Andre Spiegel                     |  This life is a test. It is only a test.
                                  |  Had this been an actual life, you would
University of Stuttgart, Germany  |  have received further instructions as to
Computer Science                  |  where to go and what to do.
                                                            -- Author unknown

	   email: spiegel@bruessel.informatik.uni-stuttgart.de

      
       
 
      



             reply	other threads:[~1994-10-25 10:36 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1994-10-25 10:36 Andre Spiegel [this message]
1994-10-25 10:07 ` Flags in Ada? David Emery
1994-10-25 16:19 ` Norman H. Cohen
1994-10-26  3:19   ` tmoran
1994-10-26  9:59     ` David Emery
1994-10-26 22:32       ` Robert Dewar
1994-10-27 13:24         ` Norman H. Cohen
1994-10-27 15:15         ` John Volan
1994-10-31  9:29         ` David Emery
1994-10-27 22:34       ` Henry G. Baker
1994-10-26 14:33     ` Robert Dewar
1994-10-26 17:43     ` Norman H. Cohen
1994-10-26 15:54   ` Andre Spiegel
1994-10-26  0:36 ` Dale Stanbrough
1994-10-26 11:01   ` Robert Dewar
1994-10-27  8:23 ` Henri Altarac
1994-10-27 23:00   ` Robert Dewar
1994-10-31  9:32     ` David Emery
  -- strict thread matches above, loose matches on Subject: below --
1994-10-25 16:22 tmoran
1994-10-27  5:05 tmoran
1994-10-27 13:29 ` Robert Dewar
1994-10-27 17:15 ` Norman H. Cohen
1994-10-28  3:51   ` Robert Dewar
1994-10-27  5:06 tmoran
1994-10-27 13:47 ` Robert Dewar
1994-10-28  2:41   ` Tucker Taft
1994-10-30 13:31     ` Robert Dewar
1994-10-28  3:59 tmoran
1994-10-28 13:43 ` Robert Dewar
1994-10-31 14:19   ` Norman H. Cohen
1994-11-02 14:06     ` Mats Weber
1994-11-03 23:08       ` Robert Dewar
1994-11-03 11:26     ` Robert Dewar
replies disabled

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