Re: [announcement] SYSAPI and SYSSVC for Windows

From: Robert A Duff (bobduff_at_shell01.TheWorld.com)
Date: 12/24/03

  • Next message: Stephen Leake: "Re: Progress with GNAT on bare MIPS"
    Date: 23 Dec 2003 18:02:45 -0500
    
    

    "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:

    > Ekkehard Morgenstern wrote:

    > > so I could've just used a tagged limited record?
    > >
    > > Like this:
    > >
    > > type T is tagged limited
    > > record
    > > A : My_Array_Type;
    > > end record;
    > >
    > > procedure F ( O : in out T ) is
    > > Ptr : My_Array_Cell_Ptr;
    > > begin
    > > Ptr := O.A(1)'Access;
    > > end;
    > >
    > > Right?
    >
    > No. It is unrelated. The thing you are getting access of has to be aliased.
    > So it is the array elements which has to be, for example:
    >
    > type T is limited private;
    > private
    > type Integer_Array is array (Integer range <>) of aliased Integer;
    > type T is limited record
    > A : Integer_Array (1..3);
    > end record;
    >
    > procedure F (O : in out T ) is
    > begin
    > ... O.A(1)'Access; -- This is OK, A(i) are aliased

    No, that's not quite good enough. The parameter O is considered to be
    nested within F, so you need 'Unchecked_Access instead of 'Access here.
    Whenever you use 'Unchecked_Access, you have to make sure you don't
    use dangling pointers -- so the & operator in C or C++ is more like
    'Unchecked_Access than 'Access in that regard.

    The point is: when you say 'Access, the compiler can prove that you
    don't have dangling pointers. Otherwise, you need 'Unchecked_Access
    (but then you better prove it yourself, or your program might do bad
    things).

    > end;
    >
    > If the array elements be tagged, then you would need not write "aliased" in
    > the array declaration.

    That's not quite right. Tagged *parameters* (like O in the above
    example) are automatically aliased. But other objects are aliased only
    if declared so (by the "aliased" keyword) or if allocated in the heap by
    "new" (whether tagged or not).

    IMHO, it was a mistake to make tagged parameters automatically aliased.
    We should, instead, have allowed the "aliased" keyword on parameters.

    Summary: To get an access value to an existing object, you must first
    make sure it's aliased (which means allocated on the heap, explicitly
    declared "aliased", or a tagged parameter). Then you must worry about
    accessibility level (which determines whether you should use 'Access or
    'Unchecked_Access).

    - Bob


  • Next message: Stephen Leake: "Re: Progress with GNAT on bare MIPS"

    Relevant Pages

    • Re: How do java programmers cope with java missing c++ const?
      ... to pass a const reference to a mutable object as can be done in c++. ... I also found the 'const' keyword in C++ to be very useful, ... It is a modifier used to change the characteristics to ... modified and must be initialized at the point of declaration. ...
      (comp.lang.java.programmer)
    • Re: Statement functions
      ... It would be a simple way to avoid ambiguity with ... array assignment, especially in the case of an internal subprogram. ... same name and you forget to give a local type declaration ... As for the keyword STMT, I'm sure that STATEMENT is a better Fortran-istic choice. ...
      (comp.lang.fortran)
    • Re: Free Access to Thompson Gale Databases During April
      ... Lesley Robertson wrote: ... The declaration of Bulgarian independence was reported in the edition ... using "Bulgaria" as the keyword, it doesn't find anything, even though ...
      (soc.genealogy.britain)
    • Re: D5 Constant expression expected
      ... suggested but with the intention of keeping the Const keyword. ... I personally would like to see Const kept for the declaration of 'true' ... identify local variables that have a local scope but a global lifetime. ...
      (comp.lang.pascal.delphi.misc)
    • Re: How do I release memory for arrays that I careated?
      ... Pucca wrote: ... declaration. ... tBuffer is declared, but it is not allocated on the heap with 'new'. ...
      (microsoft.public.win32.programmer.ole)