How can I remove C style casting in rtwtypes.h

8 views (last 30 days)
Troy
Troy on 21 Oct 2025 at 23:05
Answered: Umar on 22 Oct 2025 at 4:06
When I generate autocode, a rtwtypes.h file is produced that contains the following code:
//=======================================================================*
// Min and Max: *
// int8_T, int16_T, int32_T - signed 8, 16, or 32 bit integers *
// uint8_T, uint16_T, uint32_T - unsigned 8, 16, or 32 bit integers *
// =======================================================================
#define MAX_int8_T ((int8_T)(127))
#define MIN_int8_T ((int8_T)(-128))
#define MAX_uint8_T ((uint8_T)(255U))
#define MAX_int16_T ((int16_T)(32767))
#define MIN_int16_T ((int16_T)(-32768))
#define MAX_uint16_T ((uint16_T)(65535U))
#define MAX_int32_T ((int32_T)(2147483647))
#define MIN_int32_T ((int32_T)(-2147483647-1))
#define MAX_uint32_T ((uint32_T)(0xFFFFFFFFU))
Compiler warning are thrown about this code, which look like "warning: use of old-style cast to uint32_T...". Is there an option for the above code to be generated so it looks like:
#define MAX_int8_T static_cast<uint8_T>(127)

Answers (1)

Umar
Umar on 22 Oct 2025 at 4:06

Hi @Troy,

I checked the MathWorks documentation, and it looks like there isn’t a built-in way to generate *rtwtypes.h` using `static_cast<>*. The file is intentionally C-compatible, so it uses traditional C-style casts like (int8_T)(127) to ensure it works across compilers and platforms.

There are a few ways people handle the compiler warnings:

1. Suppress the warning for that header file—most compilers let you disable “old-style cast” warnings selectively.

2. Wrap the include with pragmas that temporarily disable the warning.

3. Manually edit `rtwtypes.h` to use `static_cast<>`, but you’d need to redo this every time the code is regenerated.

The cleanest approach in a workflow that regenerates code often ends up being either warning suppression or using pragmas, so you don’t have to maintain a custom header.

Keep me posted if you made any progress.

Categories

Find more on Deployment, Integration, and Supported Hardware in Help Center and File Exchange

Products


Release

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!