comp.lang.ada
 help / color / mirror / Atom feed
* problem with usage of aliased
@ 2001-10-26 14:47 Stijn Rammeloo
  2001-10-26 15:05 ` Ted Dennison
  0 siblings, 1 reply; 3+ messages in thread
From: Stijn Rammeloo @ 2001-10-26 14:47 UTC (permalink / raw)


Hello,

While writing an interface package for file-manipulation routines I get
following error with gnat: ..."non-local pointer cannot point to local
object."

Gnat flags the code as errornous when I apply the 'Access attribute on the
Current_Part object (which is declared as being alliased). After some
thaught I unserstood why gnat did not liked the code (I'm declaring an
object as being aliased on the stack and pass it on to the Mkdir routine so
there is a potential chance it might get out of scope, when I try to access
it later (or something like that)). However a) I'm passing this as a
parameter to something which is clearly defined as being a function (eg. no
side effects assumed). b) I'm 100% sure I cannot get a dangling pointer. So
my question pops down to this: How can I tell an ada compiler/gnat to stop
nagging in this particular case :-)

   function Mkdir(Char : Interfaces.C.Strings.Chars_Ptr)
     return Interfaces.C.Int;
   pragma Import (Convention => C,
                    Entity => Mkdir,
                    External_Name => "mkdir");

   procedure Try_Create_Next_Missing_Part(Directory: in     Path_Name) is
      Current_Part     : aliased Interfaces.C.Char_Array :=
        Interfaces.C.To_C(To_String(Get_First_Filename_Part(Directory)));
      Remaining_Parts  : Path_Name :=
Get_Remaining_Filename_Part(Directory);

      Status           : Interfaces.C.Int;
   begin

      if not Is_Directory(Directory) then
         Status :=
Mkdir(Interfaces.C.Strings.To_Chars_Ptr(Current_Part'Access));
      end if;

      if Remaining_Parts /= Null_Path_Name then
         Try_Create_Next_Missing_Part(Remaining_Parts);
      end if;
   end Try_Create_Next_Missing_Part;

Thanks in foresee,
Stijn





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

end of thread, other threads:[~2001-10-27  2:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-10-26 14:47 problem with usage of aliased Stijn Rammeloo
2001-10-26 15:05 ` Ted Dennison
2001-10-27  2:12   ` DuckE

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