If someone is interested how to use GCC preprocessor on Delphi source files. Too bad we can't do this in memory.
If someone is interested how to use GCC preprocessor on Delphi source files. Too bad we can't do this in memory.
gcc -xc -E -P -C -traditional File1 > File2
BEFORE:
program Project3;
uses
System.SysUtils;
#define DEBUG(x) {$IFDEF DEBUG}WriteLn(x);{$ENDIF}
#define LOOP(A, B, C) for A := B to C do
#define COMPARE(A, B) A <> B
var
I: Integer;
begin
LOOP(I,0,3)
begin
WriteLn(I);
end;
DEBUG('DEBUG..');
WriteLn(COMPARE(1,2));
Readln;
end.
AFTER:
program Project3;
uses
System.SysUtils;
var
I: Integer;
begin
for I := 0 to 3 do
begin
WriteLn(I);
end;
{$IFDEF DEBUG}WriteLn('DEBUG..');{$ENDIF};
WriteLn(1 <> 2);
Readln;
end.
gcc -xc -E -P -C -traditional File1 > File2
BEFORE:
program Project3;
uses
System.SysUtils;
#define DEBUG(x) {$IFDEF DEBUG}WriteLn(x);{$ENDIF}
#define LOOP(A, B, C) for A := B to C do
#define COMPARE(A, B) A <> B
var
I: Integer;
begin
LOOP(I,0,3)
begin
WriteLn(I);
end;
DEBUG('DEBUG..');
WriteLn(COMPARE(1,2));
Readln;
end.
AFTER:
program Project3;
uses
System.SysUtils;
var
I: Integer;
begin
for I := 0 to 3 do
begin
WriteLn(I);
end;
{$IFDEF DEBUG}WriteLn('DEBUG..');{$ENDIF};
WriteLn(1 <> 2);
Readln;
end.
Uwe Raabe There are situation where compiler will not inline and this is why we use it in our build system.
ReplyDeletePaul TOTH True, but the C preprocessor allows you to do a lot more than the trivial DEBUG function. It's a very slippery blade though, to be used with care.
ReplyDeletemacros allow to completely redefine everything, it becomes a nightmare to understand the source without a full documentation
ReplyDelete