
C++ developer š„ļø | cmake, best practices, dev humor | Weekly threads & tips follow if you code in C++
Los Angeles, CA
Joined August 2023
- Tweets181
- Following127
- Followers16
- Likes205
Pinned Tweet
Back after a year off. I write C++ for a living, cmake for fun (kind of), and I'll post the stuff I actually run into, not tips copied from a blog post. First real one coming later today.
1
66
An empty stateless member still costs a byte, plus padding. A comparator or allocator stored by value can push a struct from 8 bytes to 16.
[[no_unique_address]] lets it overlap and the size collapses back. The STL has done this with base classes for decades.
#cpp #cplusplus
17
The compiler assumes an int* and a float* never point at the same object. So it doesn't reload after the store, it just returns 1.
That's strict aliasing. Punning through pointers isn't a trick, it's UB. Use std::bit_cast or memcpy.
#cpp #cplusplus
Two atomic counters in one struct. Two threads, each touching only its own counter, no shared state.
Still slow, because both counters land on the same cache line and the cores ping-pong it on every write.
alignas(std::hardware_destructive_interference_size)
#cpp #cplusplus
1
61
make_shared puts the control block and the object in one allocation. Good for locality, but the block can't be freed while any weak_ptr is alive.
One weak_ptr then pins that memory long after the last shared_ptr died. With new, only the control block lingers.
#cpp #cplusplus
1
29
Returning a local by name lets the compiler skip the copy entirely.
Wrap it in std::move and you turn a free elision into a real move constructor call. gcc will even tell you to remove it.
#cpp #cplusplus
1
2
57
Those programmers are the best š
š
#developpers #cpp
2
44
Anymore to explain, why this ? Is it a joke?? :) #js #javascriptdev
3
56
Malicious PyPI package with 37,000 downloads steals AWS keys.
bleepingcomputer.com/news/seā¦
2
30















