[fpc-pascal] Proper preprocessor?

Ryan Joseph ryan at thealchemistguild.com
Thu Jun 21 17:25:00 CEST 2018



> On Jun 21, 2018, at 10:08 PM, Sven Barth via fpc-pascal <fpc-pascal at lists.freepascal.org> wrote:
> 
> For more questions you can start a thread in fpc-devel. That's the purpose of that mailing list after all. 
> 

Thanks, I’ll post there tomorrow about the technical stuff.

At first glance unless I totally underestimate something it appears to be a trivial extension to the define:= syntax but admittedly it’s edge case stuff and probably not widely used.

I did a search and found only a few hits on the topic. Since I’ve been giving theoretical examples here’s something more practical a user attempted. Can you do that without macros? If I had to guess he had some funky code and just wanted to reduce typing and copy/paste bugs.

{$define HOFFSET(rec,field) := pointer(@rec.field) - pointer(@rec)} 

type 
        s1_t = record 
                a: longint; 
                b: single; 
                c: double; 
        end; 
var 
        s1: s1_t; 
BEGIN 
        s1.a := 12345; 
        s1.b := 1.000000001; 
        s1.c := 1.000000002; 

        writeln(HOFFSET(s1, a));
END. 

Regards,
	Ryan Joseph




More information about the fpc-pascal mailing list