POV-Ray : Newsgroups : povray.text.tutorials : #declare vs. #local Mojo Server Time
21 Nov 2024 13:03:37 EST (-0500)
  #declare vs. #local Mojo (Message 1 to 5 of 5)  
From: clipka
Subject: #declare vs. #local Mojo
Date: 24 Jun 2015 20:26:44
Message: <558b4ac4$1@news.povray.org>
Some fun(?) fact to know:

If, in an include file or macro, you use #declare with an identifier 
that already happens to exist at a non-global scope, you will NOT change 
the corresponding global variable, but the most local variable of that name.

Expected that? I didn't.


Post a reply to this message

From: Le Forgeron
Subject: Re: #declare vs. #local Mojo
Date: 25 Jun 2015 02:09:11
Message: <558b9b07$1@news.povray.org>
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Le 25/06/2015 02:26, clipka a écrit :
> Some fun(?) fact to know:
> 
> If, in an include file or macro, you use #declare with an
> identifier that already happens to exist at a non-global scope, you
> will NOT change the corresponding global variable, but the most
> local variable of that name.
> 
> Expected that? I didn't.

I did, but I know how the context are stacked...

My hint: do not mix #declare and #local for the same variable, or even
parameter name of macro.

The same kind of problem happens with other languages, it's called
shadowing and it's a mess to know which one is used.

The long way would be to issue warning when using #local on a
#declare/d variable, and vice-versa, but it might requires extending
each storage to store that piece of data ( there is also #for... the
variable is kind of #local, yet should it be allowed to be updated
with #local ? )


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iJwEAQEIAAYFAlWLmwcACgkQhKAm8mTpkW32VQQA033DeqL81d9BI1pJi1x36162
CLTu8rPTzYZa0FbOTuCF+QtyqNOiVtsyx5qGjopK3UKLzvw/ss/ZLErbVmlvGD6Q
Mq7WwXAedgrFP0hTtTrUJV09Bgh98O35+SdHq7fGjcoF2eizjI41oSalzzknPePO
oi8stAyB3RcXzHx2SFY=
=l9L2
-----END PGP SIGNATURE-----


Post a reply to this message

From: Thorsten Froehlich
Subject: Re: #declare vs. #local Mojo
Date: 25 Jun 2015 07:40:01
Message: <web.558be8598cf046ea5feac50c0@news.povray.org>
clipka <ano### [at] anonymousorg> wrote:
> Some fun(?) fact to know:
>
> If, in an include file or macro, you use #declare with an identifier
> that already happens to exist at a non-global scope, you will NOT change
> the corresponding global variable, but the most local variable of that name.
>
> Expected that? I didn't.

Expected? No.
Knew? Yes.

The problem with this odd behavior is that it is actively being used. Or used to
be at least.

Thorsten


Post a reply to this message

From: clipka
Subject: Re: #declare vs. #local Mojo
Date: 25 Jun 2015 17:47:56
Message: <558c770c$1@news.povray.org>
Am 25.06.2015 um 08:09 schrieb Le_Forgeron:

> ( there is also #for... the
> variable is kind of #local, yet should it be allowed to be updated
> with #local ? )

Mucking around with the variable in a #for statement isn't really what 
I'd call best practice, but if you need to change the value, then #local 
should be the thing to use.


Post a reply to this message

From: Cousin Ricky
Subject: Re: #declare vs. #local Mojo
Date: 10 Sep 2015 17:15:00
Message: <web.55f1f1d08cf046eadb6413070@news.povray.org>
clipka <ano### [at] anonymousorg> wrote:
> Some fun(?) fact to know:
>
> If, in an include file or macro, you use #declare with an identifier
> that already happens to exist at a non-global scope, you will NOT change
> the corresponding global variable, but the most local variable of that name.
>
> Expected that? I didn't.

http://wiki.povray.org/content/Reference:Declare_and_Local_Directives#Identifier_Name_Collisions


Post a reply to this message

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