comp.lang.ada
 help / color / mirror / Atom feed
* Conditional compilation of debug traces without cpp
@ 2006-07-04 18:06 guillaume.portail
  2006-07-04 19:07 ` Ludovic Brenta
                   ` (3 more replies)
  0 siblings, 4 replies; 19+ messages in thread
From: guillaume.portail @ 2006-07-04 18:06 UTC (permalink / raw)


Hi,

I have pieces of code like this (please just follow the general idea and 
forgive syntax errors) :

package Debug is
   procedure Put_Line (M : in String);
end;

package body Debug is
   Enabled : constant Boolean := False;
   procedure Put_Line (M : in String) is
   begin
     if Enabled then
       Real_Put_Line (M);
     end;
   end;
end;

Many other units, many calls like :
   ...
   Debug.Put_Line ("PC was here, A = ", A_Type'Image(A));  -- (1)
   ...

Debug.Enabled is a compile time constant, so with a bit of -O3 pragma 
Inline or other (-gnatN), the binary implementation of Debug.Put_Line 
will be null. But never will be the elaboration of the many calls to it. 
I guess that the elaboration of theses calls is always required by the 
language, think of :
   Debug.Put_Line ("PC was here, A = " & A_Function_Call(12));  -- (2)
   Debug.Put_Line ("PC was here, A = " & A_Function_Call(1/0)); -- (3)
For my need, A_Function_Call is only for debugging purpose here, it has 
no side effect (it is a function).

How may I organize the code to obtain the effect of having Debug.* calls 
being nulls when Debug.Enabled is False ?

For your information, this is easy using cpp :

#if _DEBUG
#define DEBUG(x)	real_put_line x
#else
#define DEBUG(x)	0
...
   if (foo)
   {
     a = something;
     DEBUG(("PC was here, A=%d", b()+a));
   }
   else
     DEBUG(("no foo"));
...

And I would like not to use cpp or gnatprep, etc.

What is the trick ?
--
Thierry Bernier



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

end of thread, other threads:[~2006-07-07 21:08 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-07-04 18:06 Conditional compilation of debug traces without cpp guillaume.portail
2006-07-04 19:07 ` Ludovic Brenta
2006-07-04 19:14   ` guillaume.portail
2006-07-04 21:39     ` Björn Persson
2006-07-04 21:43       ` guillaume.portail
2006-07-04 22:01         ` Björn Persson
2006-07-05  3:10     ` Matthew Goulet
2006-07-04 20:24 ` Gautier
2006-07-04 20:54 ` Simon Wright
2006-07-05 13:03 ` Jean-Pierre Rosen
2006-07-05 19:39   ` guillaume.portail
2006-07-06  5:53     ` Martin Krischik
2006-07-07 10:32       ` Stephen Leake
2006-07-07 14:08         ` M E Leypold
2006-07-06  7:59     ` Jean-Pierre Rosen
2006-07-06 20:25       ` guillaume.portail
2006-07-07  5:00         ` Matthew Goulet
2006-07-07 13:57           ` Thierry Bernier
2006-07-07 21:08           ` Randy Brukardt

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