Sign in Join

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

Mailing lists / fpc-pascal / 2009-07

advanced macros?

3 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

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

Roland Schaefer

Hi,
reading the Programmer's Manual, I get the impression that C-style macros with {$MACRO ON} cannot do things like C

#define MY_MACRO(param1,param2...)
    code_with ( param1 && param 2 );

i.e., passing strings macros for in-macro insertion. Is this true? If yes, are there any plans to include such capabilities in the preprocessor? It would be very useful in places. On the other hand, the mighty preprocessor is one of the primary obfuscation "tools" in C.

One related question: In current FPC macros, can I include {$IFDEF}s? I did it, and without using the macro, the unit compiles ok, but I get various errors whenever I use the macro.

Cheers, thanks a lot
Roland

Reply by email

Jonas Maebe
to Roland Schaefer
Roland Schaefer wrote 7 lines
reading the Programmer's Manual, I get the impression that C-style macros with {$MACRO ON} cannot do things like C #define MY_MACRO(param1,param2...) code_with ( param1 && param 2 ); i.e., passing strings macros for in-macro insertion. Is this true?

Yes.

If yes, are there any plans to include such capabilities in the preprocessor?

No.

One related question: In current FPC macros, can I include {$IFDEF}s?

I doubt it, as I don't think that the preprocessing happens recursively.

Jonas

Reply by email

Marco van de Voort
to Roland Schaefer: reading the Programmer's Manual, I get the impression that C-style macros with {$MACRO…

In our previous episode, Roland Schaefer said:

i.e., passing strings macros for in-macro insertion. Is this true? If yes, are there any plans to include such capabilities in the preprocessor? It would be very useful in places. On the other hand, the mighty preprocessor is one of the primary obfuscation "tools" in C.

It is not that much needed anyway. Generics and inline functions do most of the stuff that the preprocessor is used for in C. Also the fact that visibility of identifiers (importing of other compilation units) is not include based makes it somewhat less useful as many people think.

The only place where I miss it somewhat is in laying out complex structured constants, preferably in some friendly way.

One related question: In current FPC macros, can I include {$IFDEF}s? I did it, and without using the macro, the unit compiles ok, but I get various errors whenever I use the macro.

Not that I know, but you of course can define it under such:

{$ifdef mydef}
 {$define macro:=something}
{$else}
 {$define macro:=something2}
{$endif}

But that is on the place of macro definition, not "local".

Reply by email