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.
my "clever" click goes here
Reraised as issue
You can do a hack fix and just do a guard that returns Just 0 if the item is negative
BangPatterns
was not doing anything in the end, used it before pattern matching and forgot to remove it.This comment is hidden because it contains spoiler information about the solution
Explain please? Thanks!!
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:Doesn't the code
violate the strict-aliasing rule whenever
shape
isn't actually a pointer to an object of typeshape_t
?Wouldn't
union
aliasing be the correct way to do this?(I'm quite new to C so this might sound as a dumb question, I'm still trying to understand type aliasing and how to do it right.)
This comment is hidden because it contains spoiler information about the solution
This solution works for
base >= 4.11.0 && < 5
(will probably still be valid forbase >= 5
, but that doesn't exist as of the time of writing this)Fixed. Thanks ;-)
And sorry for late(I haven't seen this issue report before today)
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
C# solution template has the wrong method name (should be UpperCamelCase intead of lowerCamelCase)
Why not use
fromIntegral
?Loading more items...