help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: defining global values from C++ DLD-functions


From: John W. Eaton
Subject: Re: defining global values from C++ DLD-functions
Date: Mon, 3 Mar 2003 06:54:45 -0600

On  3-Mar-2003, Tim Piessens <address@hidden> wrote:

| This does not seem to be correct. I have tested this with the following
| small example :
| 
| DEFUN_DLD(test, args, nargout, "Testing set_global_value() \n")
| {
|         set_global_value(args(0).string_value(),args(1));
| 
|         return args(1);
| }
| 
| This gave the following in octave :
| 
| octave --norc
| octave:1> a
| error: `a' undefined near line 1 column 1
| octave:1> test("a",3)
| ans = 3
| octave:2> a
| error: `a' undefined near line 2 column 1
| octave:2> a=2
| a = 2
| octave:3> who
| 
| *** dynamically linked functions:
| 
| test
| 
| *** local user variables:
| 
| a
| 
| octave:4> global a
| warning: local variable value may have changed to match global
| octave:5> a
| a = 3
| octave:6> test("a",4)
| ans = 4
| octave:7> a
| a = 4
| octave:8> who
| 
| *** dynamically linked functions:
| 
| test
| 
| *** globally visible user variables:
| 
| a
| 
| 
| So if I interpret correctly, set_global_value() does set "a" define a
| but does not declare it.

In Matlab (and Octave) you have to declare a variable "global" before
you see the global value.  In the first case, you did create a global
variable with the value 3, but you don't see it in the top-level
workspace until you declare it global there.  Try this:

  test ("a", 3)
  global a
  a

jwe



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]