Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
1 task done
ra1nb0w opened this issue Jun 27, 2024 · 4 comments · Fixed by #2693
Open
1 task done
Labels

Comments

@ra1nb0w
Copy link
Contributor

ra1nb0w commented Jun 27, 2024

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

AUDIO_DATA_FORMAT_TYPE_I_RAW_DATA = 0x80000000,

AUDIO_CHANNEL_CONFIG_RAW_DATA = 0x80000000,

How to reproduce ?

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

For more insight see https://stackoverflow.com/questions/11314545/casting-enum-definition-to-unsigned-int

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

  • I confirm I have checked existing issues, dicussion and documentation.
@HiFiPhile
Copy link
Collaborator

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

@ra1nb0w
Copy link
Contributor Author

ra1nb0w commented Jun 28, 2024

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
Copy link
Collaborator

Please make a PR so I can approve it sooner.

ra1nb0w added a commit to ra1nb0w/tinyusb that referenced this issue Jun 28, 2024
fix error

~/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.

Closes: hathach#2690
@ra1nb0w
Copy link
Contributor Author

ra1nb0w commented Jul 6, 2024

maybe we should re-open this until we find a solution

@HiFiPhile HiFiPhile reopened this Jul 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants