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

compiler warnings when in use #33

Open
laoshaw opened this issue Aug 9, 2020 · 2 comments
Open

compiler warnings when in use #33

laoshaw opened this issue Aug 9, 2020 · 2 comments

Comments

@laoshaw
Copy link

laoshaw commented Aug 9, 2020

I got lots of warnings and they're all warnings about two lines in minunit.h

In file included from minunit_example.c:1:
minunit_example.c: In function ‘test_suite’:
minunit.h:110:43: warning: comparing floating-point with ‘==’ or ‘!=’ is unsafe [-Wfloat-equal]
  110 |     MU__SAFE_BLOCK(if (minunit_real_timer == 0 && minunit_proc_timer == 0) {   \
      |                                           ^~
minunit.h:97:9: note: in definition of macro ‘MU__SAFE_BLOCK’
   97 |         block                                                                  \
      |         ^~~~~
@laoshaw
Copy link
Author

laoshaw commented Aug 9, 2020

I changed line 111 from == 0 to

if (minunit_real_timer <= MINUNIT_EPSILON &&                           \
        minunit_proc_timer <= MINUNIT_EPSILON)

and the warnings went away

@siu
Copy link
Owner

siu commented Aug 11, 2020

The warning makes sense for computed values but not so much for a float initialized to zero. Disabling the warning is verbose and compiler dependent so a solution like you propose is more elegant. I would not reuse MINUNIT_EPSILON though as it is the epsilon for floating point numbers and users may want/need to customize it. I would create another constant MINUNIT_TIME_EPSILON and use that one.

Would you like to start a PR?

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