[fpc-devel] Error when trying to compile code using macros

Lag Programming lagprogramming at aim.com
Sat Oct 11 17:55:26 CEST 2014


Hi! I don't want to fill a useless bug report, reason why I check this again, this time with you.
The following code syntax doesn't compile.


{$mode objfpc}{$H+}
{$MACRO ON} 

begin
{$define debugmacros:=
function variabletype_passingmode_one(passingmode x,y:variabletype):variabletype;localmodifier
begin if x=y then Result:=1 else result:=0;end;
function variabletype_passingmode_two(passingmode x,y:variabletype):variabletype;localmodifier
begin if x<>y then Result:=1 else result:=0;end;
}

{$define variabletype:=longint}{$define passingmode:=var}{$define localmodifier:= }
debugmacros
{$undef variabletype}{$undef passingmode}{$undef localmodifier}

{$define variabletype:=longint}{$define passingmode:=const}{$define localmodifier:=}
debugmacros
{$undef variabletype}{$undef passingmode}{$undef localmodifier}
end;

The messages:

Compile Project, Target: ConditionalJumpsAnalysis: Exit code 256, Errors: 4, Warnings: 50, Hints: 2
ConditionalJumpsAnalysis.lpr(31,2) Warning: Comment level 2 found
ConditionalJumpsAnalysis.lpr(59,10) Error: overloaded functions have the same parameter list
ConditionalJumpsAnalysis.lpr(59,10) Error: Found declaration: variabletype_passingmode_one(var LongInt;var LongInt):LongInt;
ConditionalJumpsAnalysis.lpr(61,10) Error: overloaded functions have the same parameter list
ConditionalJumpsAnalysis.lpr(61,10) Error: Found declaration: variabletype_passingmode_two(var LongInt;var LongInt):LongInt;

   Looking at the messages it appears that the syntax is checked after a partial replacement. The "passingmode" within the parenthesis is replaced but the one found in the function name is not, although they are found within the same text line. After replacing the one found within the parenthesis a syntax check is done before replacing the other one found at the same line, I guess.
   Is this a situation where the documentation is not clear enough, a limitation or a bug? Programmers guide states that macros work recursive. Or maybe I've done a mistake somewhere. Anyway, I'm using fpc and Lazarus svn, and I've checked this situation on forum before asking you.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20141011/96639ed8/attachment.html>


More information about the fpc-devel mailing list