comp.lang.ada
 help / color / mirror / Atom feed
From: root <root@vf700f.msfc.nasa.gov>
Subject: Re: Simple ADA/C Question
Date: 1997/02/26
Date: 1997-02-26T00:00:00+00:00	[thread overview]
Message-ID: <Pine.LNX.3.95.970226082729.7991A-100000@vf700f.msfc.nasa.gov> (raw)
In-Reply-To: 01bc23b2$ecc64960$64e2b8cd@p5120.bda


On 26 Feb 1997, Bob Klungle wrote:

> Without the code any comment is a guess.

Sorry, I figured this to be such a simple oversight on my part that a code
example wasn't necessary.

> However it sounds as though the
> data type being interfaced to the C function is "type mytype is integer;"
> or something like that.

I am including the code that I think is applicable so as not to make this
post too long.

  function Do_C2 return INTEGER;

  package Int_IO is new Text_IO.Integer_IO( INTEGER );
  use Int_IO;

  Integer_To_Ada : INTEGER;

  function Do_C2 return INTEGER is

    Integer_In : INTEGER;

    function C_Integer_Input return INTEGER;
    pragma IMPORT( C, C_Integer_Input, "C_Integer_Input" );

  begin
    Integer_In := C_Integer_Input;
    New_Line;
    Put_Line( "Back again, the integer returned from the C function is "
);
    Put( Integer_In );
    New_Line;
    return( Integer_In );
  end Do_C2;

begin
  while To_Lower( Answer ) = 'y'
  loop
    Integer_To_Ada := Do_C2;
    New_Line;
    Put_Line( "the integer returned from the ADA function that called ");
    Put_Line( "the C function is " );
    Put( Integer_To_Ada );
    New_Line( 2 );
    Put( "do you want to run again ( y/n )? " );
    Get( Answer );
  end loop;

> If the C function returns int, The Ada should give
> you an exception and crash the program (unless you are capturing the
> exception with something like:
> exception
>   when others => Null;
> end;)

I'm not capturing any exception and I don't get any exception that crashes
the program.  Well, I guess since the program exits as if the default
condition was met, this is not an exception crash?  As you can tell, it is
not obvious to me that an exception has occurred :).  I'll go back and
read about exceptions and handling and try to figure this out.

> Either the C code has to check for invalid input or an exception handler
> within the enclosing Ada function must handle type mismatches (it goes
> without saying a real is not an int).

I did not put any checks in the C code, I would rather work this on the
ADA side in order to learn.  Thanx.





  reply	other threads:[~1997-02-26  0:00 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-02-25  0:00 Simple ADA/C Question root
1997-02-26  0:00 ` Bob Klungle
1997-02-26  0:00   ` root [this message]
1997-02-26  0:00     ` Stephen Leake
1997-02-26  0:00       ` root
1997-02-26  0:00     ` John McCabe
1997-02-26  0:00     ` Robert Dewar
1997-02-28  0:00       ` Keith Thompson
1997-03-02  0:00         ` Robert Dewar
1997-03-04  0:00           ` Keith Thompson
1997-03-04  0:00             ` Robert Dewar
1997-03-04  0:00               ` John McCabe
1997-03-04  0:00                 ` Anders Eliasson
1997-03-04  0:00                 ` Robert Dewar
1997-03-06  0:00                   ` Keith Thompson
1997-03-06  0:00                     ` Larry Kilgallen
1997-03-09  0:00                       ` Robert Dewar
1997-03-06  0:00                     ` Robert Dewar
1997-02-27  0:00 ` Robert Dewar
1997-02-27  0:00   ` root
1997-02-27  0:00   ` root
1997-03-03  0:00 ` Robert I. Eachus
1997-03-05  0:00   ` Robert Dewar
1997-03-05  0:00 ` Jon S Anthony
1997-03-06  0:00   ` Robert Dewar
1997-03-07  0:00 ` Jon S Anthony
1997-03-07  0:00   ` Robert Dewar
1997-03-08  0:00     ` Larry Kilgallen
1997-03-07  0:00   ` 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