Recent

Author Topic: can a macro be used to define a comment delimiter synonym ?  (Read 1289 times)

440bx

  • Hero Member
  • *****
  • Posts: 1086
Hello,

I miss the C style comment delimiters /* and */. 

I tried defining a macro to have them.   Like this:
Code: Pascal  [Select]
  1. {$define /*:=(*}
  2. {$define */:=*)}
  3.  

when the compiler didn't complain about that construction, I was hopeful  it was going to work but, it didn't.  When I tried:
Code: Pascal  [Select]
  1. /* a C style comment */

The compiler was not happy.

Is there a way to define something that would make FPC recognize that sequence as an additional set of comment delimiters ?

Thank you for your help.


using FPC v3.0.4 and Lazarus 1.8.2 on Windows 7 64bit.

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 7359
Re: can a macro be used to define a comment delimiter synonym ?
« Reply #1 on: July 29, 2018, 10:48:59 am »
It probably doesn't work because macros and comments are both part of the preprocessor.   IOW the comments have already been filtered when the macros are processed.

You can always use an external preprocessor

howardpc

  • Hero Member
  • *****
  • Posts: 3102
Re: can a macro be used to define a comment delimiter synonym ?
« Reply #2 on: July 29, 2018, 10:54:57 am »
It may also be not only the compiler that is unhappy, but Lazarus Codetools, which rightly rejects invalid Pascal constructs when it encounters such a  thing as you type it. That is one of its aims, and it fulfils it well.

You can define Lazarus code templates that transform /* to (*, and */ to *) as you type, but if you want to actually see C constructs in code I think you are better programming in C than trying to force Pascal to look like C. Pascal does not look like C (except for a few borrowed symbols like += and >>).

440bx

  • Hero Member
  • *****
  • Posts: 1086
Re: can a macro be used to define a comment delimiter synonym ?
« Reply #3 on: July 29, 2018, 11:38:56 am »
It probably doesn't work because macros and comments are both part of the preprocessor.   IOW the comments have already been filtered when the macros are processed.

You can always use an external preprocessor
thank you for the reply.    The lack of C style comments are definitely not worth dealing with a preprocessor (which is quite often brutally abused.)

if you want to actually see C constructs in code I think you are better programming in C than trying to force Pascal to look like C. Pascal does not look like C (except for a few borrowed symbols like += and >>).
I'm not trying to make Pascal look like C.  Actually, I am not fond of C at all but, the language does have a few nice features  (the /* */ are not such "nice features", just something I got used to.)

One nice feature I do miss from C, is defining initialized arrays without having to specify the element count.   I wish the compiler counted the elements for me and I could just use low and high (just as with Dynamic arrays) to access them.  If such arrays where automatically considered to be static arrays when they are initialized, the compiler already has 99% of the code to implement them, all it has to do is internally establish the range to be from 0 to element count - 1.

It's no big deal to count the elements but, it would be nice if the compiler did it.  There are plenty more things in Pascal that I wish C had than vice versa.

Thank you for the information you offered.

Peace.
using FPC v3.0.4 and Lazarus 1.8.2 on Windows 7 64bit.