Skip to content

Non-GCC warnings/errors about Pointer Types #594

@THQ-WIFA

Description

@THQ-WIFA

Describe the bug
A non GCC-Compiler (e.g. IAR Embedded Workbench) will

  • find an issue with incompatible pointer type casting in TRICE_PUT16(x) in trice.h
  • report unsupported #pragma GCC ...

To Reproduce
Steps to reproduce the behavior:

  1. Create project in IAR EW or other compiler
  2. Include trice v1.1.0 by adding the files from Src and creating a suitable triceConfig.h
  3. Hit "Build"
  4. See errors/warnings

Expected behavior
Project builds without warnings.

Screenshots

Original:
Build failed with errors and warnings

With proposed solution, see below:
Build successful without errors or warnings

Desktop (please complete the following information):

  • OS: Windows 11
  • Toolchain: IAR Embedded Workbench for Renesas RX Version 5.20.1

Solution Proposal

  1. Add #ifdef __GNUC__ around the #pragma GCC, just above the macro definition of TRICE_PUT16(x) in trice.h:
#ifdef __GNUC__
#pragma GCC diagnostic ignored "-Wincompatible-pointer-types"
#endif // __GNUC__
  1. Add explicit casts from and to TriceBufferWritePosition in the macro definition of TRICE_PUT16(x) in trice.h:
#define TRICE_PUT16(x)                                                 \
	do {                                                               \
		uint16_t* p_TRICE_PUT16 = (uint16_t*)TriceBufferWritePosition; \
		*p_TRICE_PUT16++ = TRICE_HTOTS(x);                             \
		TriceBufferWritePosition = (uint32_t*)p_TRICE_PUT16;                      \
	} while (0)
Image

Optionally, you could consider changing TriceBufferWritePosition to type (void*), because pointers can be legally casted to and from that type according to https://en.cppreference.com/w/c/language/pointer.html.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions