comp.lang.ada
 help / color / mirror / Atom feed
From: "David C. Hoos, Sr." <david.c.hoos.sr@ada95.com>
Subject: Re: __FILE__ and __LINE__
Date: 1997/04/07
Date: 1997-04-07T00:00:00+00:00	[thread overview]
Message-ID: <01bc434e$d36430c0$298c71a5@dhoossr.iquest.com> (raw)
In-Reply-To: 5ia77f$go3@nlrgup.nlr.nl


Hi Carl,

Although to my knowledge gnat does not do exactly what you're describing,
it does do what is needed for one of the mist frequent uses of __FILE__ and
__LINE__, i.e., identify the source code location of failed assertions.

The source code which follows gives an example of what can be done.

Two pragmas, Debug and Assert are enabled by the -gnata compiler switch. 
The Assert pragma causes the raising of an exception at the point of a
failed assertion.  The exception is raised with an exception message
consisting of the file name, followed by a colon, followed by the line
number.

The Ada95 exception occurrence facilities permit extraction of the
exception message in the exception handler.

The contrived example illustrates the features: 

---- begin example source code -----------------
with Ada.Exceptions;
with Ada.Text_IO;
with System.Assertions;
procedure Assert is
begin
   pragma Debug (Ada.Text_IO.Put_Line ("Debug message"));
   Ada.Text_IO.Put_Line ("About to make false assertion");
   begin
      pragma Assert (False);
      null;
   exception
      when E: System.Assertions.Assert_Failure =>
         Ada.Text_IO.Put_Line
           ("Assertion at " &
            Ada.Exceptions.Exception_Message (E) &
            " failed.");
   end;
   Ada.Text_IO.Put_Line ("After false assertion handled");
end Assert;
---- end example source code ----------
-- 
David C. Hoos, Sr.,
http://www.dbhwww.com
http://www.ada95.com

Carl G.M. Welman <carl@nlr.nl> wrote in article
<5ia77f$go3@nlrgup.nlr.nl>...
> Dear all,
> 
>     I am looking for Ada equivalents for the C preprocessor macros
> "__FILE__" and "__LINE__", which result in the source file name
> (constant string) and the line number (integer) of the file/position
> they are specified, respectively. As far as I know there are no
> pragma's in Ada 95 or GNAT 3.x that do similar things. Maybe there are
> other means to do the same ? Or is this impossible in Ada 95 ?
> 
> Regards, Carl.
> 




      parent reply	other threads:[~1997-04-07  0:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-04-07  0:00 __FILE__ and __LINE__ Carl G.M. Welman
1997-04-07  0:00 ` Robert Dewar
1997-04-08  0:00   ` Carl G.M. Welman
1997-04-08  0:00     ` Robert Dewar
1997-04-09  0:00   ` Fergus Henderson
1997-04-07  0:00 ` David C. Hoos, Sr. [this message]
replies disabled

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