7
submitted 7 months ago* (last edited 7 months ago) by iliketurtiles@programming.dev to c/c_lang@programming.dev

I thought the book I'm reading had typos when I read code that uses this:

uint32_t src = 0xf0;
uint32_t dest = 0x400;

int main() {
    *&dest = *&src;
}

However if you take a look at the decompiled version on godbolt: link this correctly takes the value at the address stored in src, and copies it to the address in dest.

I'd love some help understanding what going on. The code looks like nonsense to me, "*&" should "cancel out" IMO.

========

Meanwhile here's what I thought the correct code would be:

uint32_t src = 0xf0;
uint32_t dest = 0x400;

int main() {
    *(uint32_t*) dest = *(uint32_t*) src;
}

Doesn't do what's expected, see decompiled: link. What's wrong with this?

When the RHS is a constant it works fine, and seems to be a common pattern people use.

you are viewing a single comment's thread
view the rest of the comments
[-] drre@feddit.org 1 points 7 months ago

in your second example the right most * casts src to a pointer, saying, the value 0xf0 is a memory address, the second * then attempts to get the value stored at that address.

this post was submitted on 19 Jan 2026
7 points (100.0% liked)

C Programming Language

1343 readers
4 users here now

Welcome to the C community!

C is quirky, flawed, and an enormous success.
... When I read commentary about suggestions for where C should go, I often think back and give thanks that it wasn't developed under the advice of a worldwide crowd.
... The only way to learn a new programming language is by writing programs in it.

© Dennis Ritchie

🌐 https://en.cppreference.com/w/c

founded 3 years ago
MODERATORS