[fpc-devel]C style

Peter Vreman peter at freepascal.org
Fri Jan 12 15:07:38 CET 2001


> On the other hand, macros are bad, because they create an abstraction
> layer on top of the program. I know they are useful, but still not
> enough to justify them. Everything has good and bad aspects; for
> example, what happens when I try to single step a macro? I've never
> tried, but I think they screw up things.

Macro's can be usefull for multiple platform import units. Example:

Instead of having everytime:

{$ifdef win32}stdcall;{$endif}{$ifdef unix}cdecl;{$endif}

You can write

{$ifdef win32}
  {$define decl:=stdcall}
{$endif}
{$ifdef unix}
  {$define decl:=cdecl}
{$endif}

and then use 'decl' like:

procedure importedproc();external;decl;


For debugging code with macro's: the file position is the same line, so a next operation
will go to the next line. A step operation will debug the first called procedure.


Macro's with parameters aren't implemented becuase they can be replaced better with inline
functions. IIRC there was also a note from Linus on the kernel list prefere a solution
with static;inline functions above a macro, because inlining also adds more type safety.


Peter







More information about the fpc-devel mailing list