Re: passing a struct with an array by reference



As res is of type MatlabWrap.micDataReturn which is decalred as struct, it means that res is ValueType. Value types gets allocated on stack, and because of that they have to be initialized befor they are first used, because the compiler doesn't make any assumptions about the res initial value. Because your method takes a ref parameter, then the compiler expects that this value (res) is already initialized by you, and because it isn't, then it generate that error message. Why only on LINE 1, and not on LINE 2? If you solve the problem so that LINE 1 will compile, then LINE 2 will be ok as well.

To solve that, just change
MatlabWrap.micDataReturn res;
into
MatlabWrap.micDataReturn res = new MatlabWrap.micDataReturn();

and then everything will be fine.

Regards,

Tibi
MCT, MCPD

"abhiM" <abhi.menon@xxxxxxxxx> wrote in message news:1178214742.322828.87410@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
One more question,
When i compile this function as a part of a bigger project i get the
following error
Use of unassigned local variable 'res' - This is on LINE 1, while
there is no error on LINE2

any idea whats going on?


void function(bool val)
{
MatlabWrap.micDataReturn res;
res.micData = new double[10];
if(val==true)
{
//Run a continuous loop
while (true)
{
getData(ref res); // ---------LINE 1
Thread.Sleep(1000);
}
}
else
{
getData(ref res); //----------LINE 2
}

}
}


Thanks,
AM

PS: btw I changed the 'out's to 'ref' in my previous code example.


.



Relevant Pages

  • Re: C03 abend when omitting CEE.SCEERUN from JCL
    ... The AMODE, RMODE, RENT, and RES information are link-edit information, not ... "compiler option" information. ... VS Cobol Program is actually OS/VS Cobol (amblist shows 5740CB103 as ... Do you mean VS COBOL II or OS/VS COBOL? ...
    (bit.listserv.ibm-main)
  • Re: Where are the Opteron F vs. Woodcrest reviews?
    ... (same typedef assumed) ... return res; ... sll %o1,7,%o5 ... Note that I'm not claiming that Sun's compiler is ...
    (comp.arch)
  • Re: tail call optimization
    ... (labels ((next (n l res) ... Namely, you are only thinking at the optimization quality of a compiler, not at the debuggability of the resulting code. ... developer, when looking at the stack trace, doesn't have the complete ... through the code (I'm not familiar with Lisp debugging yet, ...
    (comp.lang.lisp)
  • Re: void function returning value?
    ... > return res; ... >which is the following line within the 'Veld' class: ... >forward declaration of the friend function was done as follows: ... >Why is the compiler talking about a 'void' function? ...
    (comp.lang.cpp)
  • Re: php mysql result problem
    ... insert res: 1 ... But I'm surprised you didn't get a SQL error on this. ... It abnormally terminates processing of the page immediately after the message is sent to the client. ... Rather, if the request fails, you display your own error message and continue processing with what you can. ...
    (comp.lang.php)