Compile the function...
f1 = Compile[{},
Module[{x, temp},
x = 4.;
If[3 > 2, temp = x; Print["temp in 'if' statement: ", temp]];
Print["temp outside 'if' statement: ", temp];
];
];
Calling the function...
f1[]
Produces the following output:
temp in 'if' statement: 4.
temp outside 'if' statement: temp$3107
First, why does the function create a new local variable temp$3107
outside of the 'If' statement? Second, how can I bring the first value
for "temp" outside of the if statement?
Thanks in advance,
Scott Kasen
I assume when tmp is not used bevor, then it is *declared* and
*initialized* inside the if block like in C
f1() {
double x = 4.0;
if(3>2) {
double tmp = x;
printf("...",tmp);
}
printf("...",tmp);
}
so why don't you try
f1 = Compile[{}, Module[{x, temp = 0.0}, x = 4.;
If[3 > 2, temp = x; Print["temp in 'if' statement: ", temp]];
Print["temp outside 'if' statement: ", temp];];];
?
Cheers
Patrick