help-octave
[Top][All Lists]
Advanced

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

Strange behavior when using static variables from oct-files.


From: Peter Visser
Subject: Strange behavior when using static variables from oct-files.
Date: Mon, 5 Sep 2011 05:54:34 -0700 (PDT)

Dear all,  
I'm trying to write an oct-file and run in some strange behavior when 
using static variables from oct-files.
I use the following example from :  
http://wiki.octave.org/wiki.pl?CodaAdvanced  
#include<octave/oct.h>
  static int m = 0;
  DEFUN_DLD (static_test, args, , "")
  {
     m++;
     octave_stdout<<  m<<  std::endl;
     return octave_value();
  }  

 From the interpreter:
If i test this function from the interpreter the following happens  
 >> autoload("static_test", "static_test.oct")
 >> static_test()
1
 >> static_test()
1
 >> static_test()
1  
The number should increase but doesn't.  
 From a script file:
However if i put these commands in a script file (run_static_test.m) it 
runs just fine.  
 >> run_static_test
1
2
3  
I have tried this both under windows (windows 7) and linux (ubuntu 
natty) with the same results.
 >> version
ans = 3.2.4  
The interpreter seems to unload the oct-file (and releasing the static 
variable) after a short time out, when running in a "for loop" the 
result is as expected.  
 >> for i=1:5 static_test() end
1
2
3
4
5
 >> static_test()
1  
Cheers,  
Peter.  



reply via email to

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