I’ve got an unsigned and would like to convert that to an uint64_t (and back if possible).
How do I do that? If possible, I would like to avoid depending on undefined behaviour.
Thanks!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
For instance:
Not sure if the cast is even necessary, since this doesn’t loose information. The opposite:
will need the cast, since it’s (probably, assuming
int<uint64_t) a more narrow type.Note: I mean “need” in a weak sense; since there is a risk of losing information when converting to a more narrow type, it’s likely that compilers will warn. The cast adds a sense of “I know what I’m doing” which is how such warnings are typically silenced.