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

Incompatibility with ISO C++ #60

Open
sandsmark opened this issue Jul 29, 2021 · 2 comments
Open

Incompatibility with ISO C++ #60

sandsmark opened this issue Jul 29, 2021 · 2 comments

Comments

@sandsmark
Copy link

tml.h:91:24: warning: ISO C++ prohibits anonymous structs [-Wpedantic]
   91 |                 struct { union { char key, control, program, channel_pressure; }; union { char velocity, key_pressure, control_value; }; };
      |                        ^

Goddamn annoying that they haven't updated to C99 compatibility in even C++20, apparently.

@sandsmark
Copy link
Author

Something like this fixes it, but it's ugly:

diff --git tml.h tml.h
  index 31a7b9b..5bbd515 100644
  --- tml.h
  +++ tml.h
  @@ -88,8 +88,8 @@ typedef struct tml_message
          // - pitch_bend for TML_PITCH_BEND messages
          union
          {
  -               struct { union { char key, control, program, channel_pressure; }; union { char velocity, key_pressure, control_value; }; };
  -               struct { unsigned short pitch_bend; };
  +               struct { union { char key, control, program, channel_pressure; }; union { char velocity, key_pressure, control_value; }; } param;^M
  +               struct { unsigned short bend; } pitch;^M
          };

          // The pointer to the next message in time following this event
  @@ -331,7 +331,7 @@ static int tml_parsemessage(tml_message** f, struct tml_parser* p)
          {
                  int param;
                  if ((param = tml_readbyte(p)) < 0) { TML_WARN("Unexpected end of file"); return -1; }
  -               evt->key = (param & 0x7f);
  +               evt->param.key = (param & 0x7f);^M
                  evt->channel = (status & 0x0f);
                  switch (evt->type = (status & 0xf0))
                  {
  @@ -340,17 +340,17 @@ static int tml_parsemessage(tml_message** f, struct tml_parser* p)
                          case TML_KEY_PRESSURE:
                          case TML_CONTROL_CHANGE:
                                  if ((param = tml_readbyte(p)) < 0) { TML_WARN("Unexpected end of file"); return -1; }
  -                               evt->velocity = (param & 0x7f);
  +                               evt->param.velocity = (param & 0x7f);^M
                                  break;

                          case TML_PITCH_BEND:
                                  if ((param = tml_readbyte(p)) < 0) { TML_WARN("Unexpected end of file"); return -1; }
  -                               evt->pitch_bend = ((param & 0x7f) << 7) | evt->key;
  +                               evt->pitch.bend = ((param & 0x7f) << 7) | evt->param.key;^M
                                  break;

                          case TML_PROGRAM_CHANGE:
                          case TML_CHANNEL_PRESSURE:
  -                               evt->velocity = 0;
  +                               evt->param.velocity = 0;^M
                                  break;

                          default: //ignore system/manufacture messages
  @@ -482,7 +482,7 @@ TMLDEF int tml_get_info(tml_message* Msg, int* out_used_channels, int* out_used_
          for (;Msg; Msg = Msg->next)
          {
                  time_length = Msg->time;
  -               if (Msg->type == TML_PROGRAM_CHANGE && !programs[(int)Msg->program]) { programs[(int)Msg->program] = 1; used_programs++; }
  +               if (Msg->type == TML_PROGRAM_CHANGE && !programs[(int)Msg->param.program]) { programs[(int)Msg->param.program] = 1; used_programs++; }^M
                  if (Msg->type != TML_NOTE_ON) continue;
                  if (time_first_note == 0xffffffff) time_first_note = time_length;
                  if (!channels[Msg->channel]) { channels[Msg->channel] = 1; used_channels++; }

schellingb added a commit that referenced this issue Nov 14, 2021
Use #pragmas to avoid changing the API (#60)
@schellingb
Copy link
Owner

I committed a "fix" for this. Not a nice solution but it seemed better than breaking the API at this point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants