* * *

Author Topic: unknown macro syntax  (Read 1041 times)

Nitorami

  • Sr. Member
  • ****
  • Posts: 344
unknown macro syntax
« on: June 27, 2018, 06:29:34 pm »
I am just re-writing a part of Stefan Ziegenbalgs pascal units for matrix operations found on the contributions page. The unit is quite old, 1999-2002, and uses a lot of macros which do not compile. Does anyone understand this syntax ? Is it from a different compiler possibly, or has this been a valid fpc syntax 16 years ago ? It reads like

Code: Pascal  [Select]
  1. //define[@comp(][,#1,#2)][#0.pt[(#2)*#0.x+#1]]
  2. //ifdef[complex]
  3. //define[@rcomp(][,#1,#2)][#0.pt[(#2)*#0.x+#1].r]
  4. //define[@icomp(][,#1,#2)][#0.pt[(#2)*#0.x+#1].r]
  5. //else
  6. //define[@rcomp(][,#1,#2)][#0.pt[(#2)*#0.x+#1]]
  7. //endif
  8.  
  9. //define[@decref(][)][if (#0.id>0) and (#0.id<=MaxMatrix) and (matlist[#0.id].ref>0) then dec(matlist[#0.id].ref)]
  10. //define[@incref(][)][if (#0.id>0) and (#0.id<=MaxMatrix) then inc(matlist[#0.id].ref)]
  11.  
  12. //define[@owalert(][,#1,#2)][if (#0.id=#1.id) and ((#0.x<>#1.x) or (#0.y<>#1.y) or (#0.pt<>#1.pt)) then faterror('#2: corrupt parameters')]
  13.  

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 6500
Re: unknown macro syntax
« Reply #1 on: June 27, 2018, 06:47:18 pm »
Different compiler or separate preprocessor. Nothing like this was ever in FPC itself

Thaddy

  • Hero Member
  • *****
  • Posts: 6731
Re: unknown macro syntax
« Reply #2 on: June 27, 2018, 07:30:45 pm »
Different compiler or separate preprocessor. Nothing like this was ever in FPC itself
Nope indeed. There once was a clear statement that parameterised macro's would not be introduced any time soon.
(I have still mixed opinions about that, but otherwise you have the C trap, so I see the point).
Anyway, usually h2pas gives you some pointers on how to solve it and a function body for such macro's.
« Last Edit: June 27, 2018, 07:32:46 pm by Thaddy »
Ada's daddy wrote this:"Fools are my theme, let satire be my song."

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 6500
Re: unknown macro syntax
« Reply #3 on: June 27, 2018, 09:11:13 pm »
Different compiler or separate preprocessor. Nothing like this was ever in FPC itself
Nope indeed. There once was a clear statement that parameterised macro's would not be introduced any time soon.
(I have still mixed opinions about that, but otherwise you have the C trap, so I see the point).

I fully agree. It just leads the discussion to the next "feature" of C macros, and a new load of newbies will swear upon their life that they couldn't program without it.

Thaddy

  • Hero Member
  • *****
  • Posts: 6731
Re: unknown macro syntax
« Reply #4 on: June 27, 2018, 09:57:29 pm »
I fully agree. It just leads the discussion to the next "feature" of C macros, and a new load of newbies will swear upon their life that they couldn't program without it.
Unless you want Object Pascal ++, after all C++ is one *huge* set of macro's on top of C... :'( 8-) Or about that...
Ada's daddy wrote this:"Fools are my theme, let satire be my song."

Nitorami

  • Sr. Member
  • ****
  • Posts: 344
Re: unknown macro syntax
« Reply #5 on: June 27, 2018, 10:25:20 pm »
I agree with Thaddy's "mixed feelings" -  the macros samples here looks like rather a mess but I understand why the author used them. His matrix is a simple record

Code: Pascal  [Select]
  1. type TMatrix=record
  2.        columns, rows     : longint;  { columns, rows }
  3.        ref,sr  : longint;  { reference counts }
  4.        data      : ^float;
  5.        end;
  6.  

and he needed a simple way to access the elements M[i,j], avoiding cumbersome constructs such as M.data[M.columns*i+j]. If we cannot use getters/setters because they are too slow, neither want to do pointer arithmetics, parameterised macros may not be the worst of all solutions.

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 6500
Re: unknown macro syntax
« Reply #6 on: June 28, 2018, 08:46:05 am »
Unless you want Object Pascal ++, after all C++ is one *huge* set of macro's on top of C... :'( 8-) Or about that...

C++ isn't. The early nineties C++ reference compiler was, but that is an implementation, not a design characteristic.

Generics/templates were very new back then, and its implementation is non trivial. In that sense FPC/Delphi were lucky to be able to see how it is done with other languages.

PascalDragon

  • Full Member
  • ***
  • Posts: 184
  • Compiler Developer
Re: unknown macro syntax
« Reply #7 on: June 28, 2018, 10:23:43 pm »
I fully agree. It just leads the discussion to the next "feature" of C macros, and a new load of newbies will swear upon their life that they couldn't program without it.
Unless you want Object Pascal ++, after all C++ is one *huge* set of macro's on top of C... :'( 8-) Or about that...
I can't agree here considering I earn my money working with C++ code and thus work with much C++ code. C++ is vastly more type safe (and strict) than C and templates allow for much type safety and meta programming (though of course most of the latter is needed due to C++ not having an as rich RTTI as Object Pascal has  ;) ).

Thaddy

  • Hero Member
  • *****
  • Posts: 6731
Re: unknown macro syntax
« Reply #8 on: June 28, 2018, 10:40:14 pm »
I was just fishing and Marco took the bite..(we are really old school).  :P
Ada's daddy wrote this:"Fools are my theme, let satire be my song."

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus