Skip to content
Discussion options

You must be logged in to vote

To the future reader who found this discussion, to the question: How to best convert an underlying reference type to an lvalue quantity reference?

TL;DR answer: Don't, you shouldn't.

Details:

Reinterpreting double & to quantity<..., double> & is undefined behavior, type-punning. No amount of size, alignment, weakening aliasing, implicit lifetime, or explicit lifetime can make two objects share the same memory. The compiler may reorder, optimize the reads and writes of these two objects. Different tools, platforms, today, or in the future will impact this non-compliant code. You may diagnose these issues with the -fstrict-aliasing -Wstrict-aliasing=1 compiler options.

Out of the compliance…

Replies: 5 comments 12 replies

Comment options

You must be logged in to vote
1 reply
@chiphogg
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
6 replies
@mpusz
Comment options

@FrancoisCarouge
Comment options

@mpusz
Comment options

mpusz Apr 1, 2026
Maintainer

@chiphogg
Comment options

chiphogg Apr 1, 2026
Collaborator

@FrancoisCarouge
Comment options

Comment options

You must be logged in to vote
5 replies
@mpusz
Comment options

mpusz Apr 2, 2026
Maintainer

@FrancoisCarouge
Comment options

@FrancoisCarouge
Comment options

@mpusz
Comment options

mpusz Apr 5, 2026
Maintainer

@FrancoisCarouge
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by FrancoisCarouge
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants