Variable Not fully defined on some execution path error
46 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
John Petersen
il 11 Mar 2021
Commentato: John Petersen
il 11 Mar 2021
I have some code that is inside a simulink block that gets an error when it's compiled. It says a variable is not fully defined on some execution paths, but it's not true.
Here's a simplified version of the code:
function myfunc(logicA, logicB)
A = logicA;
B = logicB; % also input from the function
if A
X = 1;
elseif B
X = 2;
end
if (A || B)
Y = X;
end
It complies fine if I change it to
function myfunc(logicA, logicB)
A = logicA;
B = logicB; % also input from the function
X=2
if A
X = 1;
end
if (A || B)
Y = X;
end
It looks like the compiler doesn't realize that it doesn't need X if (A || B) is false?
0 Commenti
Risposta accettata
Walter Roberson
il 11 Mar 2021
disp(myfunc(1,1))
disp(myfunc(1,0))
disp(myfunc(0,1))
disp(myfunc(0,0))
function Y = myfunc(logicA, logicB)
A = logicA;
B = logicB; % also input from the function
if A
X = 1;
elseif B
X = 2;
end
if (A || B)
Y = X;
end
end
2 Commenti
Walter Roberson
il 11 Mar 2021
The code would only be acceptable if you do not unconditionally use Y afterwards.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su 2-D and 3-D Plots in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!