Sign in Join

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

Mailing lists / fpc-devel / 2012-01

Use of (* comment for $DEFINEd macros

5 messages · 4 people ·

Reply by email Subscribe to this list Your subscription

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

Paul Robinson
- Begin Message From Paul Robinson -
-- First Example --
{$MACRO ON }
{$DEFINE XX1:=' This is from Macro1' }
{$DEFINE XX2:=' This is from Macro2' }
{$DEFINE XX3:=' This is from Macro3' }
{$DEFINE XX1:=' This is from Macro1A' }
{$DEFINE XX2:=' This is from Macro2A' }
{$DEFINE XX3:=' This is from Macro3A' }
Begin
    writeln('*EXAMPLES*');
    Writeln('M1: ', XX1);
    writeln('M2: ', XX2);
    writeln('M3: ', XX3);
    writeln('*END EXAMPLES');
    readln;
end.

*EXAMPLES*
M1:  This is from Macro1A
M2:  This is from Macro2A
M3:  This is from Macro3A
*END EXAMPLES

--- Second Example ---
{$MACRO ON }
{*$DEFINE XX1:=' This is from Macro1' *)
{$DEFINE XX2:=' This is from Macro2' }
{$DEFINE XX3:=' This is from Macro3' }
{$DEFINE XX1:=' This is from Macro1A' }
{$DEFINE XX2:=' This is from Macro2A' }
{$DEFINE XX3:=' This is from Macro3A' }
Begin
    writeln('*EXAMPLES*');
    Writeln('M1: ', XX1);
    writeln('M2: ', XX2);
    writeln('M3: ', XX3);
    writeln('*END EXAMPLES');
    readln;
end.

This returns a compiler error indicating end of file.

--- Third Example ---
{$MACRO ON }
{$DEFINE XX1:=' This is from Macro1' }
{$DEFINE XX2:=' This is from Macro2' }
{$DEFINE XX3:=' This is from Macro3' }
//$DEFINE XX1:=' This is from Macro1A'
{$DEFINE XX2:=' This is from Macro2A' }
{$DEFINE XX3:=' This is from Macro3A' }
Begin
    writeln('*EXAMPLES*');
    Writeln('M1: ', XX1);
    writeln('M2: ', XX2);
    writeln('M3: ', XX3);
    writeln('*END EXAMPLES');
    readln;
end.

*EXAMPLES*
M1:  This is from Macro1
M2:  This is from Macro2A
M3:  This is from Macro3A
*END EXAMPLES

This proves conclusively that only open brace { comment is acceptable for defining macros in Free Pascal. ----
The Lessons of History teach us - if they teach us anything - that no one learns the lessons that history teaches us.
- Message Ends-

Reply by email

Felipe Monteiro de Carvalho
to Paul Robinson
Paul Robinson wrote
--- Second Example --- {$MACRO ON } {*$DEFINE XX1:=' This is from Macro1' *)

This is wrong code. You cannot open a comment with { and close it with *)

(* matches *)
{ matches only }
{* means nothing special, it is a { comment opening followed by a character * inside the comment.

Felipe Monteiro de Carvalho

Reply by email

Mark Morgan Lloyd
to Felipe Monteiro de Carvalho
Felipe Monteiro de Carvalho wrote 11 lines
On Thu, Jan 19, 2012 at 8:04 PM, Paul Robinson wrote: > --- Second Example --- > {$MACRO ON } > {*$DEFINE XX1:=' This is from Macro1' *) This is wrong code. You cannot open a comment with { and close it with *) (* matches *) { matches only } {* means nothing special, it is a { comment opening followed by a character * inside the comment.

I think that was a typo.

program testmacros;
{$MACRO ON }
{$DEFINE XX1:=' This is from Macro1' }
{$DEFINE XX2:=' This is from Macro2' }
{$DEFINE XX3:=' This is from Macro3' }
(*$DEFINE XX1:=' This is from Macro1A' *)
{$DEFINE XX2:=' This is from Macro2A' }
{$DEFINE XX3:=' This is from Macro3A' }
Begin
     writeln('*EXAMPLES*');
     Writeln('M1: ', XX1);
     writeln('M2: ', XX2);
     writeln('M3: ', XX3);
     writeln('*END EXAMPLES');
     readln;
end.

0 2> fpc testmacros
Free Pascal Compiler version 2.7.1 [2011/12/23] for sparc Copyright (c) 1993-2011 by Florian Klaempfl and others Target OS: Linux for SPARC
Compiling testmacros.pas
testmacros.pas(25) Fatal: Unexpected end of file
Fatal: Compilation aborted
Error: /usr/local/bin/ppcsparc returned an error exitcode (normal if you did not specify a source file to be compiled)

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

Paul Robinson
to Felipe Monteiro de Carvalho: This is wrong code. You cannot open a comment with { and close it with *) (* matches *) {…

From: Felipe Monteiro de Carvalho

Paul Robinson wrote
--- Second Example --- {$MACRO ON } {*$DEFINE XX1:=' This is from Macro1' *)

This is wrong code. You cannot open a comment with { and close it with *)

I may have misread the brace when I typed it, but this one I checked Line 6 three times to ensure the comment opens with (* and closes with *)

{$MACRO ON }
{$DEFINE XX1:=' This is from Macro1' }
{$DEFINE XX2:=' This is from Macro2' }
{$DEFINE XX3:=' This is from Macro3' }
(*$DEFINE XX1:=' This is from Macro1A' *)
{$DEFINE XX2:=' This is from Macro2A' }
{$DEFINE XX3:=' This is from Macro3A' }
Begin
    writeln('*EXAMPLES*');
    Writeln('M1: ', XX1);
    writeln('M2: ', XX2);
    writeln('M3: ', XX3);
    writeln('*END EXAMPLES');
    readln;
end.

And again, it tells me the source code terminates prematurely.

Reply by email

Hans-Peter Diettrich
to Paul Robinson: - Begin Message From Paul Robinson - -- First Example -- {$MACRO ON } {$DEFINE XX1:='…
This proves conclusively that only open brace { comment is acceptable for defining macros in Free Pascal.

The scanner for comments is highly optimized (manually), resulting in unwanted inconsistent and untested behaviour :-(

The preprocessor is broken since the time, when somebody decided to make the scanner a class, and didn't know how to update the preprocessor part accordingly. I've supplied an patch to make the preprocessor work again, but it didn't find its way into the compiler yet :-(

DoDi

Reply by email