bugGNU Octave - Bugs: bug #38595, Global variables in function

 
 

bug #38595: Global variables in function

Submitted by:  None
Submitted on:  Tue 26 Mar 2013 10:01:00 AM UTC  
 
Category: NoneSeverity: 3 - Normal
Priority: 5 - NormalItem Group: None
Status: InvalidAssigned to: None
Originator Name: KonstantinOriginator Email: -unavailable-
Open/Closed: ClosedRelease: 3.6.4
Operating System: GNU/Linux

Add a New Comment(Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

Tue 26 Mar 2013 12:42:54 PM UTC, comment #1:

This is not a bug. You need to use the global keyword both inside and outside the function.

http://www.gnu.org/software/octave/doc/interpreter/Global-Variables.html#Global-Variables

Jordi GutiƩrrez Hermoso <jordigh>
Project Administrator
Tue 26 Mar 2013 10:01:00 AM UTC, original submission:

I explain my problem in examples:
If I define m variable once

m=2;
m
function y=f(Pi)
global m;
m
m=m+Pi;
y=m;
end
y=f(5)
m

I get an answer:
source ("test4.m")

>>>m = 2

m = 2
y = 7
m = 7

If I define the variable m twice or more:

m=2;
m=3;
m
function y=f(Pi)
global m;
m
m=m+Pi;
y=m;
end
y=f(5)
m

I get bug:

>>>m = 3

m = [](0x0)
y = [](0x0)
m = 3

Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach File(s):
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by jordigh (Posted a comment)
  • -unavailable- added by None (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 2 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Tue 26 Mar 2013 12:42:54 PM UTCjordighStatusNone=>Invalid
      Open/ClosedOpen=>Closed

    Back to the top


    Powered by Savane 3.1-cleanup1