Learning that you can use unions in C for grouping things into namespaces
1–10 of 150 posts
Re: Learning that you can use unions in C for grouping things into namespaces
#2Re: Learning that you can use unions in C for grouping things into namespaces
#3Doesn’t matter for C, but in C++ this could make your contexpr functions UB since you can only use one member of a union in constexpr contexts (the “active” member).
Re: Learning that you can use unions in C for grouping things into namespaces
#4Doesn’t matter for C, but in C++ this could make your contexpr functions UB since you can only use one member of a union in constexpr contexts (the “active” member).
In C++ we have namespaces for 30 years now, no need for such tricks.
Re: Learning that you can use unions in C for grouping things into namespaces
#5Doesn’t matter for C, but in C++ this could make your contexpr functions UB since you can only use one member of a union in constexpr contexts (the “active” member).
In C++ we have namespaces for 30 years now, no need for such tricks.
C++ namespaces are a way to avoid library A's symbol "cow" clashing with library B's symbol "cow" without everything being named library_a_cow and library_b_cow all over the place which is annoying. I agree C would be nicer with such a namespace feature.
However this technique is about what happens when you realise your structure members x and y should be inside a sub-structure position, and you want both:
d = calculate_distance(s.x, s.y); // Old code
and
d = calculate_distance(s.position.x, s.position.y); // New
... to work while you transition to this naming.
Re: Learning that you can use unions in C for grouping things into namespaces
#6Doesn’t matter for C, but in C++ this could make your contexpr functions UB since you can only use one member of a union in constexpr contexts (the “active” member).
Re: Learning that you can use unions in C for grouping things into namespaces
#7Re: Learning that you can use unions in C for grouping things into namespaces
#8Earlier quoted context omitted.
In C++ we have namespaces for 30 years now, no need for such tricks.
Hmm. How do C++ namespaces help with the structure naming problem in this example? They seem completely orthogonal. C++ namespaces are a way to avoid library A's symbol "cow" clashing with library B's symbol "cow" without everything being named library_a_cow and library_b_cow all over the place which is annoying. I agree C would be nicer with such a namespace feature. However this technique is about what happens when…
Re: Learning that you can use unions in C for grouping things into namespaces
#9Re: Learning that you can use unions in C for grouping things into namespaces
#10https://github.com/floooh/sokol-samples/blob/bfb30ea00b5948f...
(also note the 'inplace initialization' which follows the state struct definition using C99's designated initialization)