POV-Ray : Newsgroups : povray.general : What use is ifdef ? Server Time
25 Nov 2024 15:22:27 EST (-0500)
  What use is ifdef ? (Message 1 to 5 of 5)  
From: FNH
Subject: What use is ifdef ?
Date: 3 Mar 2014 12:50:00
Message: <web.5314c0a9c473c8865f52a9c30@news.povray.org>
I know what ifdef does (the example below shows me using it)...

//#declare text2use = 2;

box     {
        <-10,0,11>,<10,10,10>

        #ifdef(text2use)
                texture { pigment { White } }
        #else
                texture { pigment { Green } }
        #end

        }

.... but I'm struggling to understand when you would use it. Why would you refer
to a variable you've not defined?  Isn't that just sloppy coding.

Has anyone got/had a real-use case for this command? I'd love to know what I'm
missing out on.


Post a reply to this message

From: Le Forgeron
Subject: Re: What use is ifdef ?
Date: 3 Mar 2014 12:55:05
Message: <5314c1f9$1@news.povray.org>
Le 03/03/2014 18:49, FNH nous fit lire :
> I know what ifdef does (the example below shows me using it)...
> 
> //#declare text2use = 2;
> 
> box     {
>         <-10,0,11>,<10,10,10>
> 
>         #ifdef(text2use)
>                 texture { pigment { White } }
>         #else
>                 texture { pigment { Green } }
>         #end
> 
>         }
> 
> .... but I'm struggling to understand when you would use it. Why would you refer
> to a variable you've not defined?  Isn't that just sloppy coding.
> 
> Has anyone got/had a real-use case for this command? I'd love to know what I'm
> missing out on.
> 
> 

you can define variable in code, but also in command line.

the most traditional use is the classical protection of include file: if
the value already exist, skip the definition.


Post a reply to this message

From: FNH
Subject: Re: What use is ifdef ?
Date: 3 Mar 2014 13:05:01
Message: <web.5314c4368b4b40c85f52a9c30@news.povray.org>
Le_Forgeron <jgr### [at] freefr> wrote:
> Le 03/03/2014 18:49, FNH nous fit lire :
> > I know what ifdef does (the example below shows me using it)...
> >
> > //#declare text2use = 2;
> >
> > box     {
> >         <-10,0,11>,<10,10,10>
> >
> >         #ifdef(text2use)
> >                 texture { pigment { White } }
> >         #else
> >                 texture { pigment { Green } }
> >         #end
> >
> >         }
> >
> > .... but I'm struggling to understand when you would use it. Why would you refer
> > to a variable you've not defined?  Isn't that just sloppy coding.
> >
> > Has anyone got/had a real-use case for this command? I'd love to know what I'm
> > missing out on.
> >
> >
>
> you can define variable in code, but also in command line.
>
> the most traditional use is the classical protection of include file: if
> the value already exist, skip the definition.

Excellent, I'll have try using as a command line switch. Thanks :)


Post a reply to this message

From: MichaelJF
Subject: Re: What use is ifdef ?
Date: 3 Mar 2014 14:45:01
Message: <web.5314dabf8b4b40c872f270270@news.povray.org>
"FNH" <nomail@nomail> wrote:
> I know what ifdef does (the example below shows me using it)...
>
> //#declare text2use = 2;
>
> box     {
>         <-10,0,11>,<10,10,10>
>
>         #ifdef(text2use)
>                 texture { pigment { White } }
>         #else
>                 texture { pigment { Green } }
>         #end
>
>         }
>
> .... but I'm struggling to understand when you would use it. Why would you refer
> to a variable you've not defined?  Isn't that just sloppy coding.
>
> Has anyone got/had a real-use case for this command? I'd love to know what I'm
> missing out on.

It is just to ensure that a certain thing exists. Your code will use this thing
and you can define a default value, if you have not defined it earlier - may be
at the command line or with an earlier include or within the code itself.

Best regards,
Michael


Post a reply to this message

From: Alain
Subject: Re: What use is ifdef ?
Date: 3 Mar 2014 19:19:00
Message: <53151bf4@news.povray.org>

> I know what ifdef does (the example below shows me using it)...
>
> //#declare text2use = 2;
>
> box     {
>          <-10,0,11>,<10,10,10>
>
>          #ifdef(text2use)
>                  texture { pigment { White } }
>          #else
>                  texture { pigment { Green } }
>          #end
>
>          }
>
> .... but I'm struggling to understand when you would use it. Why would you refer
> to a variable you've not defined?  Isn't that just sloppy coding.
>
> Has anyone got/had a real-use case for this command? I'd love to know what I'm
> missing out on.
>
>

It's often used in includes. Some uses are:

Make sure that you don't re-parse a file that's been included before. 
Take a look at the base includes, they all have this construct:
#ifndef(Include_File_Flag)
#declare Include_File_Flag=version;
...body of the include file goes here...
#end

Have some defaults parameters that you can optionaly define before 
calling an include or a macro.



Alain


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.