Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2000-09

Nul sub-routine

5 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

IoDream

Hello to all,

I would like to know if we can define a sub-routine to be nul, so that when compiling this routine hold no is what a macro do, but macros aren't implemented yet in FPC.
This could be used, for example, in a C-like "assert" function that when NDEBUG is defined the function is inserted, and when it isn't the function waste no space. I include a DJGPP version of the function prototype. In other words; this is equivalent to the lines below, but is easier to write, and looks much better in your source:
{$IFDEF NDEBUG}

  Assert(blabla);

{$ENDIF}

Best Regards,
IoDream.

Florian Klaempfl
to IoDream
IoDream wrote 15 lines
Hello to all, I would like to know if we can define a sub-routine to be nul, so that when compiling this routine hold no is what a macro do, but macros aren't implemented yet in FPC. This could be used, for example, in a C-like "assert" function that when NDEBUG is defined the function is inserted, and when it isn't the function waste no space. I include a DJGPP version of the function prototype. In other words; this is equivalent to the lines below, but is easier to write, and looks much better in your source: {$IFDEF NDEBUG} Assert(blabla); {$ENDIF}

FPC supports Assert. If you compile without -Sa it is ignored.

IoDream
to Florian Klaempfl

OK, that's good ! Thanks !

But I would like to do the same with some profiling subroutines. You understand: if I compile with the symbol PROFILE defined all the profiling code is compiled, and if the symbol is undefined then no extra code is generated.

Any idea ?

Earlier message 42 lines
----- Original Message ----- From: Florian Klaempfl To: Sent: Wednesday, September 20, 2000 11:37 PM Subject: Re: [fpc-pascal]Nul sub-routine > IoDream wrote: > > > > Hello to all, > > > > I would like to know if we can define a sub-routine to be nul, so that > > when compiling this routine hold no is what a macro do, > > but macros aren't implemented yet in FPC. > > This could be used, for example, in a C-like "assert" function that when > > NDEBUG is defined the function is inserted, and when it isn't the function > > waste no space. I include a DJGPP version of the function prototype. > > In other words; this is equivalent to the lines below, but is easier to > > write, and looks much better in your source: > > {$IFDEF NDEBUG} > > Assert(blabla); > > {$ENDIF} > > > > FPC supports Assert. If you compile without -Sa it is ignored. > > _______________________________________________ > fpc-pascal maillist - > http://lists.freepascal.org/mailman/listinfo/fpc-pascal ______________________________________________________________________________ Vous avez un site perso ? 2 millions de francs à gagner sur i(france) ! Webmasters : ZE CONCOURS ! http://www.ifrance.com/_reloc/concours.emailif
Florian Klaempfl
to IoDream
Show quoted text 9 lines
OK, that's good ! Thanks ! But I would like to do the same with some profiling subroutines. You understand: if I compile with the symbol PROFILE defined all the profiling code is compiled, and if the symbol is undefined then no extra code is generated. Any idea ?

You can use macros. Of course, this requires that you include the macro definition in all files and compile with -Sm.

{$ifdef profiling}
{$define profile_code:=myprofileprocedure}
{$else profiling}
{$define profile_code:= }
{$endif profiling}

I'am not sure if the docs contain info about macros.

Remark that FPC macros doesn't support parameters as in C. If someone has to time to implement this, feel free to do so :)....