Problem with compiler C to use int16_t type for translation in Q15 format
Show older comments
Hello,
I have a problem with compiler C. I have this error message
Error using legacycode.LCT.legacyCodeImpl
The data type "int16_t" is neither a built-in data type, nor defined by
a Simulink.AliasType, Simulink.NumericType, Simulink.Bus object, or an
enumerated data type:
--> int16_t y1 = ControlloDig(int16_t u1)
Error in legacy_code (line 101)
[varargout{1:nargout}] = legacycode.LCT.legacyCodeImpl(action,
varargin{1:end});
Error in Discretizza_controllo_generazione_sfun (line 77)
legacy_code('sfcn_cmex_generate', def);
I did a function that works in Q15 format but, when I use the script to compile it, Matlab shows an error on the data type "int16_t". If you need the other files i can upload them.
Answers (2)
Sebastian K
on 26 May 2017
Hi there,
I am afraid it will not be possible to provide a very helpful answer based on the limited information you have provided. The error message itself is not quite useful. Ideally you should provide a detailed explanation of:
- What you are trying to do
- How you are trying to do it
- At what stage of the process you encounter the error
Just by looking at the error message, I am guessing that you are probably trying to use the Legacy Code Tool to build a C MEX S-function from some hand-written C code.
The main issue looks like the "int16_t" data type is not defined. One potential reason for this could be that you are missing a header file in your C code that contains the data type definition. Try adding the following "include" directive to your C code.
#include <tmwtypes.h>
I hope this helps.
Sebastian
Bisca
on 27 May 2017
7 Comments
Walter Roberson
on 27 May 2017
int16_t and so on are in stdint.h which was introduced in C99. Possibly you do not have the flags set to use C99 ?
Bisca
on 29 May 2017
Walter Roberson
on 29 May 2017
You would generally be able to tell from the complete command output of the compiling process. On unix derived compilers look for std=c99 or std=c11 with std=c89 being before that. I do not recall the flag used for the visual studio compilers
Walter Roberson
on 29 May 2017
Unfortunately it appears that Microsoft decided not to support C99, except for the parts that are also C++; see https://herbsutter.com/2012/05/03/reader-qa-what-about-vc-and-c99/. So do not expect a Visual Studio flag to indicate C99 conformance. However, the articles does note that stdint.h is supported.
I see that VS2015 started adding conformance flags, starting with /std:c++14 (no earlier conformance flag appears to be available.)
I am not clear as to which compiler you are using ?
Bisca
on 1 Jun 2017
Jan
on 1 Jun 2017
int16_T (uppercase T) is defined in tmwtypes.h .
Bisca
on 6 Jun 2017
Categories
Find more on Simulink Compiler in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!