octave-maintainers
[Top][All Lists]
Advanced

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

Re: Initializing structs with mixed non-empty fields and {} leads to emp


From: Richard Crozier
Subject: Re: Initializing structs with mixed non-empty fields and {} leads to empty structs
Date: Mon, 26 Mar 2012 00:17:33 +0100
User-agent: Mozilla/5.0 (Windows NT 5.1; rv:7.0.1) Gecko/20110929 Thunderbird/7.0.1


On 25/03/2012 22:55, PhilipNienhuis wrote:
> I'm not sure if this is a bug, so I ask here first:
> 
> ## Case 1
> octave-3.6.1.exe:1> s = struct ("a", {}, "b", 0)
> s =
>   0x0 struct array containing the fields:
>     a
>     b
> octave-3.6.1.exe:2> s.b = 65
> error: invalid assignment to cs-list outside multiple assignment
> 
> ## Case 2
> octave-3.6.1.exe:4> s = struct ("a", [], "b", 0)
> s =
>   scalar structure containing the fields:
>     a = [](0x0)
>     b = 0
> octave-3.6.1.exe:5> s.b = 65
> s =
>   scalar structure containing the fields:
>     a = [](0x0)
>     b =  65
> octave-3.6.1.exe:6> s.a = {}
> s =
>   scalar structure containing the fields:
>     a = {}(0x0)
>     b =  65
> 
> In case 1, assigning {} to a new struct doesn't work, while it can be
> assigned once the struct exists (see Case 2). That looks inconsistent to me. 
> s(1).b = 65 succeeds, so apparently the initial size (dimension) of the
> struct was set to 0x0 even while a non-empty field was specified in the
> constructing statement.
> 
> Philip
> 
> --
> View this message in context: 
> http://octave.1599824.n4.nabble.com/Initializing-structs-with-mixed-non-empty-fields-and-leads-to-empty-structs-tp4504166p4504166.html
> Sent from the Octave - Maintainers mailing list archive at Nabble.com.
> 

I have coincidentally come up against this bizarre behaviour in ML
today, it seems ML creates an array of structures for cell array input
to the struct function (rather than just putting the cell array in a
field). Perhaps Octave also works like this for compatibility.

e.g. in ML

>> s = struct('a', [1 2 3 4 4 5 5], 'b', 'jfdkafjda', 'c', {1, 2, 'fda'})

s =

1x3 struct array with fields:
    a
    b
    c


each struct member has the same a nd b fields and one of each of the c
cell array members. This was not intuitive to me.

Your code in ML gives:

>> s = struct ('a', {}, 'b', 0)

s =

0x0 struct array with fields:
    a
    b

>> s.b = 65
??? A dot name structure assignment is illegal when the structure is empty.
  Use a subscript on the structure.


Richard


-- 
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.



reply via email to

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