comp.lang.ada
 help / color / mirror / Atom feed
* Calling C's fopen from Ada (Aonix compiler)
@ 2000-12-12  1:15 Wayne Magor
  2000-12-12  3:06 ` Robert Dewar
  2000-12-19  7:54 ` Gerhard Häring
  0 siblings, 2 replies; 6+ messages in thread
From: Wayne Magor @ 2000-12-12  1:15 UTC (permalink / raw)


I need to call a C procedure which requires a file pointer (the file
must be opened by
the caller).  So I want to call C's fopen from Ada (I'm using the Aonix
Ada compiler on
Windows NT).

This causes an access error exception in the program that requires the
file pointer, however,
if I just write a little C function called "my_fopen" which looks just
like fopen and is just
a call-through function, it works fine.  Below is an example of how the
interfaces to the
standard C function and mine work.

I could go with the work-around and link in an extra obj file that just
does the call-through,
but I'd rather figure out why this doesn't work.  Can anyone give me
some insight as to what
I don't know about this?  In the debugger, the pointers appear to point
to a similar block
of data for my_fopen and the C fopen, but the C one just will not work.
.
.
.
  package C renames Interfaces.C;

  F : File_Ptr;

  function my_fopen (Name : in C.Char_Array;
                     Mode : in C.Char_Array) return File_Ptr;
  pragma Import (C, my_fopen, "my_fopen");

  function fopen (Name : in C.Char_Array;
                  Mode : in C.Char_Array) return File_Ptr;
  pragma Import (C, fopen, "fopen");

begin

  F := my_fopen("my_file.txt" & C.nul, "r" & C.nul);
  F := fopen("my_file.txt" & C.nul, "r" & C.nul);





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

end of thread, other threads:[~2000-12-20  0:31 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-12-12  1:15 Calling C's fopen from Ada (Aonix compiler) Wayne Magor
2000-12-12  3:06 ` Robert Dewar
2000-12-19  7:54 ` Gerhard Häring
2000-12-19 15:33   ` Robert Dewar
2000-12-19 18:18   ` David Botton
2000-12-20  0:31     ` Robert Dewar

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