From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,96ffd854e360102b,start X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2000-12-11 18:37:51 PST Path: supernews.google.com!sn-xit-02!supernews.com!216.227.56.88.MISMATCH!telocity-west!TELOCITY!cyclone.bc.net!newsfeed.stanford.edu!headwall.stanford.edu!unlnews.unl.edu!newsfeed.ksu.edu!nntp.ksu.edu!onews.collins.rockwell.com!not-for-mail From: Wayne Magor Newsgroups: comp.lang.ada Subject: Calling C's fopen from Ada (Aonix compiler) Date: Mon, 11 Dec 2000 19:15:52 -0600 Organization: Rockwell International Message-ID: <3A357C48.D4CAC970@nowhere.com> NNTP-Posting-Host: gatekeeper.collins.rockwell.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailer: Mozilla 4.51 [en]C-CCK-MCD (WinNT; U) X-Accept-Language: en Xref: supernews.google.com comp.lang.ada:2964 Date: 2000-12-11T19:15:52-06:00 List-Id: 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);