Sign in Join

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

Mailing lists / fpc-devel / 2014-10

Error when trying to compile code using macros

3 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

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

Lag Programming

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 xy 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.

Reply by email

Jonas Maebe
to Lag Programming
Lag Programming wrote 16 lines
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.

Macro's never replace text in the middle of an identifier.

Jonas

Reply by email

Michael Schnell
to Jonas Maebe
Jonas Maebe wrote
Macro's never replace text in the middle of an identifier.

Does the optional extended FPC macro processor not support a concatenation syntax (such as ## with the C macro preprocessor) ?

In theory it could be possible to use the gnu C macro preprocessor in certain cases.

-Michael

Reply by email