-
Notifications
You must be signed in to change notification settings - Fork 2k
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
core/macros: fix SIGNOF() macro when applied to size_t #18849
Conversation
core/include/macros/math.h
Outdated
@@ -31,7 +31,7 @@ extern "C" { | |||
unsigned int: 1, \ | |||
unsigned long: 1, \ | |||
unsigned long long: 1, \ | |||
default: (long long)(a) < 0 ? -1 : 1) | |||
default: (signed long)(a) < 0 ? -1 : 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't this be "signed long long" ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought so too, but when I would do that I'd still get the error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you handle long long
as special case to avoid loosing precision on the default
? Otherwise we may end up with false results for 64 bit numbers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
default: (0LL < ((long long) a)) ? (-1) : (1) )
worked for me no it did not
i checked and found long long
to be longer than unsigned long
(4 vs 8 bytes)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hm this will make zero negative signed, but I hope that won't cause any issues…
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no it is wrong i missed turning the < around
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea I figured. Still a > 0
will be false and return -1 for a == 0
.
But I supposed we could say the sign of 0 is undefined…
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the compiler also fails for uint32_t
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doesn't the _generics system know about typedefs?
would
work for the usecases? |
but the cast might also lead to wrong result if a is > uint64_max / 2 |
No, then it's not longer compile time const in so much that it can be used to statically initialize the size of an array. |
something seems to be realy wrong it does not fail for uint64_t (but the cast may not be valid in that case ( values > uint64_max / 2 will be considered negative)) but if fails for uint32_t, uint16_t |
may be the warning should just be disabled or document that it only work up to long |
Murdock results✔️ PASSED 8f8bb6c tests/unittests: core: add test for SIGNOF(size_t)
ArtifactsThis only reflects a subset of all builds from https://ci-prod.riot-os.org. Please refer to https://ci.riot-os.org for a complete build for now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK, but please address and inline comment and squash before merging
@benpicco DIV_ROUND without signum
|
Contribution description
This is a strange one, for some reason when doing
none of the
_Generic
s would match and we getTesting procedure
The updated unit test should compile.
Issues/PRs references