Sign in Join

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

Mailing lists / fpc-devel / 2010-02

RFC: changing conditional compilation

5 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

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

Flávio Etrusco

Hello,

The problem I'm trying to solve is that I find the $define system to have a (an unnecessary) propensity for errors caused by typos; if you don't agree please ignore my YAAP (yet another annoying proposition).

Because of this propensity for erros with the $define system (and because it causes unnecessary recompilation), I usually prefer to use 'consts' whenever possible; of course this doesn't work for many cases, including multiplatform development, where you have to omit whole function declarations and calls. Now there's Macros, but they wouldn't solve the problem either, unless you'd use some crazy scheme with "$if declared" or something AFAICS.
What I wished is to change (or add a directive to change) the way $ifdef/ifndef work, enforcing that symbols are always declared, like it was a boolean. So one would have to use e.g. {$define EnableFeature false} to "undefine" it, otherwise conditionals would fail.

I can see it causing some minor annoyances, can anybody see any bigger problem? (apart from thinking the idea is pointless, which should have caused you to stop reading in the first paragraph ;-)

Best regards,
Flávio

Reply by email

Jonas Maebe
to Flávio Etrusco
Flávio Etrusco wrote 7 lines
Now there's Macros, but they wouldn't solve the problem either, unless you'd use some crazy scheme with "$if declared" or something AFAICS. What I wished is to change (or add a directive to change) the way $ifdef/ifndef work, enforcing that symbols are always declared, like it was a boolean. So one would have to use e.g. {$define EnableFeature false} to "undefine" it, otherwise conditionals would fail.

As far as I know, that's how macros behave.

E.g.:

{$macro on}
{$define xxx:=1}
{$if xxx}
begin
end.
{$endif}

If you undefine "xxx", you'll get a compile time error.

Downside: they don't work with booleans for some reason, only with integers...

Jonas

Reply by email

Jonas Maebe
Flávio Etrusco wrote 20 lines
> As far as I know, that's how macros behave. > > E.g.: > > {$macro on} > > {$define xxx:=1} > > {$if xxx} > begin > end. > {$endif} > > If you undefine "xxx", you'll get a compile time error. > > Downside: they don't work with booleans for some reason, only with > integers... Hi Jonas, As you can imagine I'd prefer to "solve" the $ifdef "problem" ;-)

To be honest: no, I can't imagine why you would prefer that. The entire difference between $ifdef and $if is that $if checks the value of something (and hence will give an error if the symbol is undefined) and $ifdef checks whether it is defined or not. As far as I can tell, you would simply like to be able to use boolean constants in $if expressions.

Yes, I noticed the problem with bools - and that it would fail with "string found but boolean expected" if the name was undefined -,

The latter is the behaviour you want, no?

Jonas

PS: please reply to the list

Reply by email

Flávio Etrusco
to Jonas Maebe

2010/2/9 Jonas Maebe :

Show quoted text 25 lines
On 09 Feb 2010, at 01:24, Flávio Etrusco wrote: >> As far as I know, that's how macros behave. >> >> E.g.: >> >> {$macro on} >> >> {$define xxx:=1} >> >> {$if xxx} >> begin >> end. >> {$endif} >> >> If you undefine "xxx", you'll get a compile time error. >> >> Downside: they don't work with booleans for some reason, only with >> integers... > > Hi Jonas, > As you can imagine I'd prefer to "solve" the $ifdef "problem" ;-) To be honest: no, I can't imagine why you would prefer that.

Because everybody automatically uses $ifdef and most of the code would work with minor intervention. E.g. we usually use something like {.$define EnableDocking} to undefine the symbol. You'd just have to force it explicitly $undef or some kind of {$define EnableDocking disable} or 'false', or something.

Show quoted text 5 lines
The entire difference between $ifdef and $if is that $if checks the value of something (and hence will give an error if the symbol is undefined) and $ifdef checks whether it is defined or not. As far as I can tell, you would simply like to be able to use boolean constants in $if expressions.

This would solve the problem for my code, not conditionals I'm trying to use on 3rd party code...

> Yes, I noticed the problem with bools - and that it would fail with > "string found but boolean expected" if the name was undefined -, The latter is the behaviour you want, no?

Yes - apart from puzzling error message to the casual users - but it'd require to set a convention on the Macro value for on/off and back to possibly causing errors due to typos.

Jonas PS: please reply to the list_______________________________________________

Sorry, I just skip the list sometimes when I think the post will be just noise to other people. I'd certainly get back to it when I have something relevant to say ;-)

Best regards,
Flávio

Reply by email

Flávio Etrusco
to Jonas Maebe: To be honest: no, I can't imagine why you would prefer that. The entire difference…
Show quoted text 9 lines
> Hi Jonas, > As you can imagine I'd prefer to "solve" the $ifdef "problem" ;-) To be honest: no, I can't imagine why you would prefer that. The entire difference between $ifdef and $if is that $if checks the value of something (and hence will give an error if the symbol is undefined) and $ifdef checks whether it is defined or not. As far as I can tell, you would simply like to be able to use boolean constants in $if expressions.

Hope you rethink your opinion the next time you forget to add an {$I} or mess up a define name ;-)

Best regards,
Flávio

Reply by email