Recent

Author Topic: Macros confuse error message line number?  (Read 615 times)

Eugene Loza

  • Hero Member
  • *****
  • Posts: 729
    • My games in Pascal
Macros confuse error message line number?
« on: April 16, 2024, 07:08:13 pm »
In some situations, like the example below, the error message points to $define instead of actual line where the error has happened:

Code: Pascal  [Select][+][-]
  1. program Project1;
  2. var
  3.   A: TObject;
  4.  
  5. {$macro on}
  6. {$define AObject:=(A as TObject)}
  7.  
  8. begin
  9.   A := TObject.Create(nil)
  10.   AObject.Tag := 0;
  11.   A.Free;
  12. end.

I wonder if there a way to effectively find the actual faulty line in code? In the example it's trivial - a forgotten semicolon and incorrect Create syntax. But when the macro is located inside of an include file and used a few dozens of times throughout a relatively large unit, debugging some trivial typos becomes slightly harder than necessary.
« Last Edit: April 16, 2024, 07:41:51 pm by Eugene Loza »
My FOSS games in FreePascal&CastleGameEngine: https://decoherence.itch.io/ (Sources: https://gitlab.com/EugeneLoza)

MarkMLl

  • Hero Member
  • *****
  • Posts: 8007
Re: Macros confuse error message line number?
« Reply #1 on: April 16, 2024, 07:20:43 pm »
Regrettably, that's the way it is and the way it's likely to stay.

Macro error placement can get very nasty if- as an example- a macro is associated with the name of a unit. Regrettably, in Real-World programming, such things are sometimes unavoidable.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

PascalDragon

  • Hero Member
  • *****
  • Posts: 5752
  • Compiler Developer
Re: Macros confuse error message line number?
« Reply #2 on: April 16, 2024, 08:13:25 pm »
In some situations, like the example below, the error message points to $define instead of actual line where the error has happened:

Correct, that is simply how macros work and we have no interest to change that.

 

TinyPortal © 2005-2018