Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #70575
| Newsgroups | comp.lang.c++ |
|---|---|
| Date | 2019-12-18 15:36 -0800 |
| References | <cYwKF.3051$vj3.487@fx10.dcg> <c7c7929d-b01c-4a19-a557-60da44ed6c9f@googlegroups.com> <FpyKF.281$Rl7.139@fx06.dcg> |
| Message-ID | <bb1f4444-bfe5-4ac8-8cc2-68d92a0dfd33@googlegroups.com> (permalink) |
| Subject | Re: Probably UB but I am finding it hard to give a fuck (C++ swizzle) |
| From | Öö Tiib <ootiib@hot.ee> |
On Thursday, 19 December 2019 01:15:06 UTC+2, Mr Flibble wrote:
> On 18/12/2019 22:24, Öö Tiib wrote:
> > On Wednesday, 18 December 2019 23:35:23 UTC+2, Mr Flibble wrote:
> >> Hi!
> >>
> >> The following is the base class of my vector class (the mathematical vector not the container) so I can do things like:
> >>
> >> vec3 v1 = { 1.0, 2.0, 3.0 };
> >> vec2 v2 = v1.xy;
> >> double z = v1.z;
> >> vec4 v3 = v1.xyzz;
> >>
> >> So we have an anonymous union of an anonymous struct and some swizzles and I suspect it is full of UB but I am finding it hard to care as I cannot see any other way of doing this.
> >>
> >> Collective thoughts/wisdom?
> >
> > It likely violates strict aliasing, casting between unrelated types
> > and also how unions are allowed to be used in C++.
> >
> > So even if it appears to work with your compilers on cases
> > you did test it might mess it up differently in other use-cases
> > that you did not test yet. Also it may change with next patch to
> > any of your compilers.
> >
> > Can you say what is the issue with typical interface
> > implementable to work same on all C++11 or better compilers:
> >
> > vec3 v1 = { 1.0, 2.0, 3.0 };
> > vec2 v2 = v1.xy();
> > double z = v1.z();
> > vec4 v3 = v1.xyzz();
> >
> > Couple of extra parentheses can't be problem, otherwise we all
> > would switch to Kotlin (that is *way* less verbose than C++).
>
> Because
>
> v1.set_z(42.0);
>
> is ew and
>
> v1.z() = 42.0
>
> is even more ew.
I trust v1.moveBy(0.0, 0.0, 39.0) or
v1.moveTo(1.0, 2.0, 42.0) depending what was the point
is simpler to understand than v1.z = 42.0 anyway.
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Probably UB but I am finding it hard to give a fuck (C++ swizzle) Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk> - 2019-12-18 21:34 +0000
Re: Probably UB but I am finding it hard to give a fuck (C++ swizzle) Öö Tiib <ootiib@hot.ee> - 2019-12-18 14:24 -0800
Re: Probably UB but I am finding it hard to give a fuck (C++ swizzle) Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk> - 2019-12-18 23:14 +0000
Re: Probably UB but I am finding it hard to give a fuck (C++ swizzle) Öö Tiib <ootiib@hot.ee> - 2019-12-18 15:36 -0800
Re: Probably UB but I am finding it hard to give a fuck (C++ swizzle) Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk> - 2019-12-19 06:18 +0000
Re: Probably UB but I am finding it hard to give a fuck (C++ swizzle) "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2019-12-19 10:49 +0100
Re: Probably UB but I am finding it hard to give a fuck (C++ swizzle) Manfred <noname@add.invalid> - 2019-12-19 14:29 +0100
Re: Probably UB but I am finding it hard to give a fuck (C++ swizzle) "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2019-12-18 15:38 -0800
Re: Probably UB but I am finding it hard to give a fuck (C++ swizzle) Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk> - 2019-12-19 06:19 +0000
Re: Probably UB but I am finding it hard to give a fuck (C++ swizzle) "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2019-12-23 10:34 -0800
Re: Probably UB but I am finding it hard to give a fuck (C++ swizzle) "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2019-12-28 00:30 -0800
Re: Probably UB but I am finding it hard to give a fuck (C++ swizzle) Mr Flibble <flibble@i42.removethisbit.co.uk> - 2019-12-28 15:53 +0000
Re: Probably UB but I am finding it hard to give a fuck (C++ swizzle) "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2020-01-31 23:00 -0800
Re: Probably UB but I am finding it hard to give a fuck (C++ swizzle) Manfred <noname@add.invalid> - 2019-12-19 14:25 +0100
Re: Probably UB but I am finding it hard to give a fuck (C++ swizzle) woodbrian77@gmail.com - 2019-12-20 08:22 -0800
Re: Probably UB but I am finding it hard to give a fuck (C++ swizzle) Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk> - 2019-12-21 13:23 +0000
Re: Probably UB but I am finding it hard to give a fuck (C++ swizzle) "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2020-01-11 15:08 -0800
Re: Probably UB but I am finding it hard to give a fuck (C++ swizzle) Bonita Montero <Bonita.Montero@gmail.com> - 2020-02-10 18:35 +0100
Re: Probably UB but I am finding it hard to give a fuck (C++ swizzle) "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2020-02-10 14:07 -0800
Re: Probably UB but I am finding it hard to give a fuck (C++ swizzle) "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2020-01-31 21:42 -0800
csiph-web