Sign in Join

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

Mailing lists / lazarus / 2017-02

$IF for Linux and FreeBSD platforms?

7 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

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

Graeme Geldenhuys

Hi,

Is the following allowed in LCL specific code?

{$IFDEF LCLGTK2}
  {$IF declared(Linux) or declared(FreeBSD)}
   {$define something}
  {$endif}
{$endif}

The IDE shows that CodeTools knows about the FreeBSD variable, but the code doesn't seem to work, because later in the code the "something" compiler define seems undefined during compilation - yet the IDE correctly shades the {$IFDEF something} wrapped code as active.

Regards,
Graeme

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/ My public PGP key: http://tinyurl.com/graeme-pgp

Reply by email

Graeme Geldenhuys
to Graeme Geldenhuys
Graeme Geldenhuys wrote
The IDE shows that CodeTools knows about the FreeBSD variable, but the code doesn't seem to work,

Doing the following though does work, but it means I have to duplicate all $DEFINE lines in two places, which I don't really want to do.

{$IFDEF LCLGTK2}
  {$IFDEF Linux}
    {$DEFINE something}
    ...snip.
  {$ENDIF}
  {$IFDEF FreeBSD}
    {$DEFINE something}
    ...snip.
  {$ENDIF}
{$ENDIF}

Regards,
Graeme

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/ My public PGP key: http://tinyurl.com/graeme-pgp

Reply by email

Ondrej Pokorny
to Graeme Geldenhuys
Graeme Geldenhuys wrote 18 lines
On 2017-02-16 10:54, Graeme Geldenhuys via Lazarus wrote: > The IDE shows that CodeTools knows about the FreeBSD variable, but the > code doesn't seem to work, Doing the following though does work, but it means I have to duplicate all $DEFINE lines in two places, which I don't really want to do. {$IFDEF LCLGTK2} {$IFDEF Linux} {$DEFINE something} ...snip. {$ENDIF} {$IFDEF FreeBSD} {$DEFINE something} ...snip. {$ENDIF} {$ENDIF}

Well, you mixed up DEFINED and DECLARED macros. The following should work:

{$IFDEF LCLGTK2}
   {$IF DEFINED(Linux) or DEFINED(FreeBSD)}
    {$define something}
   {$endif}
{$endif}

Ondrej

Reply by email

Unknown author
to Graeme Geldenhuys
Graeme Geldenhuys wrote
On 2017-02-16 11:18, Ondrej Pokorny via Lazarus wrote: > Well, you mixed up DEFINED and DECLARED macros.

Sorry newbie question regarding these $IF directives:

can someone explain why you would use "$IF defined" instead of $IFDEF...

Obviously there are likely reasons for using one over the other.

Dope!!! Thanks for spotting that. I need more coffee. ;-)

Coffee being used as a crutch is bad. Use it for an extra burst, not as an hourly/daily reliance.
IMHO

Or IMAO
A := 'arrogant';

Reply by email

Graeme Geldenhuys
to Unknown author
Lars wrote
can someone explain why you would use "$IF defined" instead of $IFDEF...

In that case a piece of code applied to both Linux and FreeBSD platforms. I didn't see the need to duplicate the code with IFDEF statements - thus making code management more work.

So use "$IF defined" to accept more that one define for a block of code.

> Dope!!! Thanks for spotting that. I need more coffee. ;-) Coffee being used as a crutch is bad. Use it for an extra burst, not as an hourly/daily reliance.

I live on coffee and Red Bull at the moment. Trying to survive lots of sleepless nights due to a little human teething! :-(

Or how does the other saying go:
Computer Programmer: We convert coffee and pizza into source code. :-)

Regards,
Graeme

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/ My public PGP key: http://tinyurl.com/graeme-pgp

Reply by email

Sven Barth
to Unknown author: Sorry newbie question regarding these $IF directives: can someone explain why you would…

Am 28.02.2017 20:37 schrieb "Lars via Lazarus" <

Show quoted text 15 lines
: On 2017-02-16 05:35, Graeme Geldenhuys via Lazarus wrote: > > On 2017-02-16 11:18, Ondrej Pokorny via Lazarus wrote: >> >> Well, you mixed up DEFINED and DECLARED macros. > > Sorry newbie question regarding these $IF directives: can someone explain why you would use "$IF defined" instead of $IFDEF... Obviously there are likely reasons for using one over the other.

$IFDEF FOO is an abbreviation for $IF DEFINED(FOO). The latter also allows to combine multiple checks using AND and OR (and also allowing comparisons with constant values) while the former can always only check for a single define.

Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20170228/6e47305f/attachment.html>

Reply by email