views:

305

answers:

4

Is there a macro preprocessor for Delphi 7?

There isn't one built in so maybe there's a possibilty to use a third party or some other languages preprocessor (like c preprocessor).

If there's one, how to set it up for Delphi 7?

I'm trying to do function inlining (for speed). Macro preprocessor seems to be the only easy option for delphi.

Thanks, Egon

A: 

I haven't heard of any third-party macros in Delphi 7, but versions 2007+ have automatic inlining if that's an option.

Alan Clark
D2005 already supports inlining
Marco van de Voort
+2  A: 

You can always run an external macro processor, such as m4 or even (shudder) cpp on your code before you compile it. I wouldn't recommend this however - in my experience the benefits of inlining (which is what you seem to want to do) are quite small, and can be offset by slowdowns caused increases in code size.

anon
It's worthwhile, but only for short leaf methods that use relatively lowlevel types. (IOW no automated). It's great for pointer based iterators and the like. As soon as any procedure is called, the speedup is gone
Marco van de Voort
I used finally m4. It seemed to have the most separated syntax. The speed can be 10x for small functions. For example a simple function like PointInRect.
egon
A: 

You can use the JEDI Pascal Preprocessor which is part of the JEDI Code Library.

You can fetch the current JCL release from its SourceForge project page, and you can browse the JPP course code here.

Mihai Limbășan
A: 

Here's how I used m4:

// uses lookup for counting bits
function PopCount(const Number: Cardinal): Byte;
begin
  Result := WordBitCount[Number and $FFFF] + WordBitCount[Number shr 16];
end;
{ M4 macro
define(PopCount, (WordBitCount[$@ and $FFFF] + WordBitCount[$@ shr 16]))
}

It's still easily compilable, but can be sped up with m4.

egon