[fpc-devel] __LINE__ and __FILE__ macros

Joerg Schuelke joerg.schuelke at gmx.de
Fri Apr 29 15:45:32 CEST 2011


Am Fri, 29 Apr 2011 09:58:08 +0200 (CEST)
schrieb marcov at stack.nl (Marco van de Voort):

> I use an IDE macro to insert a predefined line, and then I just
> change the constants I will log. The advantage of that way is that
> you have full intellisense to specify the vars to dump, something
> that is always hard with a macro.

Ok, so far. But: if you write code like

{$define _dp:=writeln(stderr,{$I %FILE%}:20,' [',{$I %LINE%},'] ')}

and somewhere else you use the dp macro, I would expect that it prints
out the line number and file name of the place where I used it and not
where I defined it. Yesterday I looked in the sources and found that
this is because insertmacro is always called with line and file
parameters from the defining context.
I think it would be more useful if the {$I %FILE%} and {$I %LINE%}
directives expand to the bottom level file name and line number, not
the one of the mac.text where they are used and even not from where
they may be included.
An other possibility is to make all levels of line and file info
accessible trough a construct like {$I %FILE%nnn%}, where nnn% is an
optional integer level description.

regards
	Jörg



More information about the fpc-devel mailing list