Sign in Join

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

Mailing lists / fpc-pascal / 2005-03

undefining multiple defines

10 messages · 6 people · –

Reply by email Subscribe to this list Your subscription

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

Marc Santhoff

Hi,

I'm using several defines like this:

{$define M1}
{ $define M2}
{ $define M3}
{ $define M4}
...

Any time I have to change them, I have to touch all one by one, because they're mutually exclusive.

Is there method of saying: {$undef M1..M15}?
Or a better basic approach?

TIA,
Marc

Jeff Miller
to Marc Santhoff
Show quoted text 11 lines
I'm using several defines like this: {$define M1} { $define M2} { $define M3} { $define M4} Any time I have to change them, I have to touch all one by one, because they're mutually exclusive. Or a better basic approach?

Maybe I am missing something, but why not just have a single define statement, which you change to define the one symbol that you want for the current compile? If they are mutually exclusive, you never need more than one define, right?

Jeff

Marc Santhoff
to Jeff Miller
Show quoted text 15 lines
> I'm using several defines like this: > > {$define M1} > { $define M2} > { $define M3} > { $define M4} > > Any time I have to change them, I have to touch all one by one, because > they're mutually exclusive. > > Or a better basic approach? Maybe I am missing something, but why not just have a single define statement, which you change to define the one symbol that you want for the current compile? If they are mutually exclusive, you never need more than one define, right?

No, you don't. Thinking about it a little longer makes sense sometimes (I'll do next time ;). And explaning the complete problem does, too.

These defines are used several times spread over a bunch of units. It is possible to use one in unit a and another one in unit b. What i want to achive is to undefine any previously set defines and be sure there is only one of them active.

this is used to include some dependant functions from only one central include file holding all possible versions. And it has to work from the command line or makefile.

unit a;
...
{$define M1}
...
end.
unit b;
...
{$undef M1-M15}
{$define M2}
...
end.

Marc

Marco van de Voort
to Marc Santhoff
unit b; ... {$undef M1-M15}

Such constructs won't work, for the same reason that variablenames with numbers in it can't be used as such.

For the compiler it is an alphanumerical identifier, and the number(s) have no meaning.

Nico Aragón
to Marc Santhoff: No, you don't. Thinking about it a little longer makes sense sometimes (I'll do next time…
Marc Santhoff wrote
this is used to include some dependant functions from only one central include file holding all possible versions. And it has to work from the command line or makefile.

Then you can write a program (invoked from the command line or makefile) that generates the define lines before the compiler processes them. Hope it helps.

saludos, Nico Aragón
Jeff Pohlmeyer
Show quoted text 6 lines
unit b; ... {$undef M1-M15} {$define M2} ... end.

Can't you just put all your $undef's in a *.inc file, and then $include it anywhere you need to undef all?

unit b;
...
{$include undefs.inc}
{$define M2}
...
end.
__________________________________ Celebrate Yahoo!'s 10th Birthday! Yahoo! Netrospective: 100 Moments of the Web http://birthday.yahoo.com/netrospective/
Marc Santhoff
to Marco van de Voort: Such constructs won't work, for the same reason that variablenames with numbers in it…
Show quoted text 9 lines
> unit b; > ... > {$undef M1-M15} Such constructs won't work, for the same reason that variablenames with numbers in it can't be used as such. For the compiler it is an alphanumerical identifier, and the number(s) have no meaning.

According to the Programmers Guide MACPAS-Mode alows to use $SETC M=8 and I assume that "$if M=8" can check it.

Unfortunately my program is compiled with -S2 and I fear these two modes are no combinable (I'll test later), are they?

If all fails I have to use the solution Nico suggested, the not so beloved find/grep/sed approach ... mostly ending up witk awk.

Thank you all,
Marc

Olle Raab
to Marc Santhoff: According to the Programmers Guide MACPAS-Mode alows to use $SETC M=8 and I assume that…

05-03-03 10.55, skrev Marc Santhoff följande:

Show quoted text 13 lines
Am Do, den 03.03.2005 schrieb Marco van de Voort um 08:32: >> unit b; >> ... >> {$undef M1-M15} > > Such constructs won't work, for the same reason that variablenames with > numbers in it can't be used as such. > > For the compiler it is an alphanumerical identifier, and the number(s) have > no meaning. According to the Programmers Guide MACPAS-Mode alows to use $SETC M=8 and I assume that "$if M=8" can check it.

In MACPAS it would be "$IFC M=8" but otherwise you are correct.

Unfortunately my program is compiled with -S2 and I fear these two modes are no combinable (I'll test later), are they?

No, sorry.

You can however define a macro, afaik:

{$DEFINE M := 8}

To get this work you then have to turn macros on in the unit, and live with that:

{$MACRO ON}

Olle

Marc Santhoff
to Olle Raab
Show quoted text 22 lines
05-03-03 10.55, skrev Marc Santhoff följande: > Am Do, den 03.03.2005 schrieb Marco van de Voort um 08:32: >>> unit b; >>> ... >>> {$undef M1-M15} >> >> Such constructs won't work, for the same reason that variablenames with >> numbers in it can't be used as such. >> >> For the compiler it is an alphanumerical identifier, and the number(s) have >> no meaning. > > According to the Programmers Guide MACPAS-Mode alows to use $SETC M=8 > and I assume that "$if M=8" can check it. In MACPAS it would be "$IFC M=8" but otherwise you are correct. > Unfortunately my program is compiled with -S2 and I fear these two modes > are no combinable (I'll test later), are they? No, sorry.

Pretty evident.

Show quoted text 8 lines
You can however define a macro, afaik: {$DEFINE M := 8} To get this work you then have to turn macros on in the unit, and live with that: {$MACRO ON}

Yes, I was thinking about a solution using macros, but had some other work to do. And can live with macros on very well (I think before trying ;), the most rememberable and easy to use solution is welcome here.

Thanks,
Marc