MATLAB Answers


Why C codes generated by Matlab Coder contain strange data type like real_T?

Asked by Lixin
on 4 Oct 2012


I'm just learning the Matlab coder to convert matlab code to c codes. Everything looks good but in the generated c codes the data type like real_T, int_T appare a lot of times. These are not regular data types of C language. I'm wondering do I have to change these in order to compile these codes in a c complier? Thanks.



No products are associated with this question.

1 Answer

Answer by Walter Roberson
on 4 Oct 2012
 Accepted answer

The .h file will have the appropriate typedef .

Using typedef types such as real_T instead of float or double, makes it easier to generate code that can be compiled on different machines that might have different floating point properties. Instead of the C code generator having to know all the details of each machine, instead the code is generated in terms of "intent" of the section, and a machine-specific .h file translates the intents into local implementation details.

For example, if the code generated double directly, then to port the code to a different machine, you would need to know whether at that particular point in the code, "double" was needed for precision purposes; or if instead the original target machine only had "double" instructions in hardware and so "double" was being used for performance reasons; or if instead the code was needed to talk to an operating system interface that specifically expects 8 bytes exactly. But if the code generates real_T at that point then the intent becomes clear "whatever data type is handy to handle single precision or higher", which a target-specific .h file can then know is "float" or "double" as appropriate for the hardware instruction set, that the precision is not too important and the size representation is not too important. Change a single #define or a typedef and you are ready for a different hardware, without the code generation facility having to know anything about the very specific chip that will be compiled to.

  1 Comment

on 4 Oct 2012

Thanks Walter! That's very helpful!

Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!