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

Replace min/max macros with inline functions #6

Merged
merged 1 commit into from
Jan 31, 2021
Merged

Replace min/max macros with inline functions #6

merged 1 commit into from
Jan 31, 2021

Conversation

carmiker
Copy link
Contributor

This pull request fixes the warning below:

emu2413/emu2413.c:228:25: warning: comparison of unsigned expression in '< 0' is always false [-Wtype-limits]
  228 | #define max(i, j) (((i) > (j)) ? (i) : (j))
      |                         ^
emu2413/emu2413.c:825:24: note: in expansion of macro 'max'
  825 |         slot->eg_out = max(0, ((int)slot->eg_out - (slot->eg_out >> s) - 1));
      |                        ^~~

This fixes a minor bug I experience in Phantasy Star for the Sega Master System after importing the code into my emulator.
I use musl libc and compile with:

-std=c99 -Wall -Wextra -Wshadow -Wmissing-prototypes -pedantic

References:
https://dustri.org/b/min-and-max-macro-considered-harmful.html
https://stackoverflow.com/questions/3437404/min-and-max-in-c

@okaxaki
Copy link
Member

okaxaki commented Jan 31, 2021

Thanks! I thought these macros are safe since they are scoped only in the emu2413.c. However, considering the type-safety, it's better to avoid to use them.

@okaxaki okaxaki merged commit 9e0bdfe into digital-sound-antiques:master Jan 31, 2021
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

Successfully merging this pull request may close these issues.

None yet

2 participants