Main Content

Unknown Output Type for coder.ceval

Issue

You see this error message:

Output of 'coder.ceval' has unknown type. The enclosing
expression cannot be evaluated.
Specify the output type by assigning the output of
'coder.ceval' to a variable with a known type.

Cause

This error message occurs when the code generator cannot determine the output type of a coder.ceval call.

Solution

Initialize a temporary variable with the expected output type. Assign the output of coder.ceval to this variable.

Example

Assume that you have a C function called cFunctionThatReturnsDouble. You want to generate C library code for a function foo. The code generator returns the error message because it cannot determine the return type of coder.ceval.

function foo
%#codegen
callFunction(coder.ceval('cFunctionThatReturnsDouble'));
end

function callFunction(~)
end

To fix the error, define the type of the C function output by using a temporary variable.

function foo
%#codegen
temp = 0;
temp = coder.ceval('cFunctionThatReturnsDouble');
callFunction(temp);
end

function callFunction(~)
end

You can also use coder.opaque to initialize the temporary variable.

Example Using Classes

Assume that you have a class with a custom set method. This class uses the set method to ensure that the object property value falls within a certain range.

classdef classWithSetter
   properties
      expectedResult = []
   end
   properties(Constant)
      scalingFactor = 0.001
   end
   methods
      function obj = set.expectedResult(obj,erIn)
         if erIn >= 0 && erIn <= 100
            erIn = erIn.*obj.scalingFactor;
            obj.expectedResult = erIn;
         else
            obj.expectedResult = NaN;
         end
      end
   end
end

When generating C library code for the function foo, the code generator produces the error message. The input type into the set method cannot be determined.

function foo
%#codegen
obj = classWithSetter;
obj.expectedResult = coder.ceval('cFunctionThatReturnsDouble'); 
end

To fix the error, initialize a temporary variable with a known type. For this example, use a type of scalar double.

function foo
%#codegen
obj = classWithSetter;
temp = 0;
temp = coder.ceval('cFunctionThatReturnsDouble'); 
obj.expectedResult = temp; 
end

See Also

|