Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
cppreference on strict aliasing
Since the type of
shape
is a struct that contains (directly or recursively) a member of typeshape_t
, the cast does not violate strict aliasing rules, as struct types are aggregate types.(At least according to the definitions on cppreference)
Furthermore, since the type of
shape
is a struct that contains (directly or recursively) a member of typeshape_t
, the alignment ofshape
is guaranteed to meet the alignment requirements ofshape_t
.Lastly, since the very first member of the type of
shape
(directly or recursively) is of typeshape_t
, the offset to that member is guaranteed to be 0.Thus, that pointer cast is valid.
closing to keep a single issue
Reraised as issue
You can do a hack fix and just do a guard that returns Just 0 if the item is negative
Disclaimer: one cannot simply understand aliasing, so I'm not entirely sure.
Given that
(const shape_t *)shape
is&((const right_triangle_t *)shape)->shape
, the underlying typeshape_t
is the same, so there's no aliasing. The only question is whether the type cast is valid. So there's C11 ("n1570.pdf") 6.7.2.1.15:Fixed. Thanks ;-)
And sorry for late(I haven't seen this issue report before today)
This comment is hidden because it contains spoiler information about the solution
Good point, I guess for no reason.
I was probably using it for something else in which I needed to specify that a is Fractional, and then I just left it as it was :P
Fixed
No issue. This is part of the task.
(Generally you are right, of course. ;-))
Random tests added.
Thanks,
good advice,
I'll add random tests
Thanks for your post!
This comment is hidden because it contains spoiler information about the solution
Yes. It's a good idea :)