hathach / tinyusb

An open source cross-platform USB stack for embedded system
https://www.tinyusb.org
MIT License
4.66k stars 996 forks source link

audio.h: error: ISO C restricts enumerator values to range of 'int' before C23 [-Werror=pedantic] #2690

Closed ra1nb0w closed 2 days ago

ra1nb0w commented 3 days ago

Operating System

Linux

Board

STM32H563 Nucleo

Firmware

custom

What happened ?

These lines issue a warning/error when strictly following the ISO C standard before 23 https://github.com/hathach/tinyusb/blob/756ad3553d095b69cf3276e3967381eba958232e/src/class/audio/audio.h#L492 https://github.com/hathach/tinyusb/blob/756ad3553d095b69cf3276e3967381eba958232e/src/class/audio/audio.h#L643

How to reproduce ?

built with gcc -Wfatal-errors -Wall -Wextra -Wpedantic -std=c11

Debug Log as txt file (LOG/CFG_TUSB_DEBUG=2)

~/dsp/libs/tinyusb/src/class/audio/audio.h:643:53: error: ISO C restricts enumerator values to range of 'int' before C23 [-Werror=pedantic]
  643 |   AUDIO_CHANNEL_CONFIG_RAW_DATA                   = 0x80000000, // TODO
      |                                                     ^~~~~~~~~~
compilation terminated due to -Wfatal-errors.

Screenshots

No response

I have checked existing issues, dicussion and documentation

HiFiPhile commented 3 days ago

I read the post ,does it work with (int)(1U << 31U) ?

ra1nb0w commented 3 days ago

works fine. Also tested with

/**
 * build with
 * gcc -Wfatal-errors -Wall -Wextra -Wpedantic -std=c11
 */

#include <stdio.h>
#include <stdint.h>

#define BYTE_TO_BINARY_PATTERN "%c%c%c%c%c%c%c%c"
#define BYTE_TO_BINARY(byte)  \
  ((byte) & 0x80 ? '1' : '0'), \
  ((byte) & 0x40 ? '1' : '0'), \
  ((byte) & 0x20 ? '1' : '0'), \
  ((byte) & 0x10 ? '1' : '0'), \
  ((byte) & 0x08 ? '1' : '0'), \
  ((byte) & 0x04 ? '1' : '0'), \
  ((byte) & 0x02 ? '1' : '0'), \
  ((byte) & 0x01 ? '1' : '0') 

typedef enum
{
  A = (int)(1U << 31U),
} size_test;

int main(void)
{
  printf(BYTE_TO_BINARY_PATTERN " " BYTE_TO_BINARY_PATTERN " " BYTE_TO_BINARY_PATTERN " " BYTE_TO_BINARY_PATTERN "\n",
         BYTE_TO_BINARY(A >> 24), BYTE_TO_BINARY(A >> 16), BYTE_TO_BINARY(A >> 8), BYTE_TO_BINARY(A)
  );
}

Do you need a PR or do the change yourself? Anyway, thank you very much for all your work!

HiFiPhile commented 3 days ago

Please make a PR so I can approve it sooner.