Christian F. TangšŸ‘¤ (@christ10n) header
Christian F. TangšŸ‘¤ (@christ10n) profile picture

C++ developer šŸ–„ļø | cmake, best practices, dev humor | Weekly threads & tips follow if you code in C++

Los Angeles, CA
Joined August 2023
Photo by Christian F. TangšŸ‘¤ (@christ10n)Photo by Christian F. TangšŸ‘¤ (@christ10n)Photo by Christian F. TangšŸ‘¤ (@christ10n)Photo by Christian F. TangšŸ‘¤ (@christ10n)Photo by Christian F. TangšŸ‘¤ (@christ10n)Photo by Christian F. TangšŸ‘¤ (@christ10n)Photo by Christian F. TangšŸ‘¤ (@christ10n)Photo by Christian F. TangšŸ‘¤ (@christ10n)Photo by Christian F. TangšŸ‘¤ (@christ10n)Photo by Christian F. TangšŸ‘¤ (@christ10n)
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
1
2
36
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
C++26 reflection isn't a someday thing. gcc 16.1 shipped it back in April, and this compiles today with -std=c++26 -freflection. Field names and values at compile time. No macros, no codegen, no external tool. #cpp #cpp26
1
1
51
^^T gives you a std::meta::info handle for the type. nonstatic_data_members_of hands one back for each field, and [:m:] splices it into real code. identifier_of(m) is just the field name as a string. That's the whole trick.
1
1
31
file(GLOB_RECURSE SRC src/*.cpp) is the cmake trap I keep finding in new repos. Add a .cpp, cmake never regenerates, the file is silently never compiled. CONFIGURE_DEPENDS fixes it but re-globs every build. Just list your sources. #cmake #cpp
47
cmake gotcha that got me again today. target_link_libraries with PUBLIC vs PRIVATE isn't just style, it changes what gets propagated to anything that links your target. Learned that the hard way on a build that pulled in half of Boost it didn't need. #cmake #cpp
1
1
87
Will carbon replace #cpp šŸ¤”?
2
48
I find it perplexing that there is a considerable number of individuals who wish for the discontinuation of C++. Personally, I hold a deep appreciation for C++, as it is integral to my work.
45
Hahaha šŸ˜‚šŸ˜‚
40
🤧 this code will never do anything...šŸ˜… #dev #cpp #joke
37
Pls, no more legacy code in 2025 🤧🤧
2
34
Those programmers are the best šŸ˜…šŸ˜… #developpers #cpp
2
44
Anymore to explain, why this ? Is it a joke?? :) #js #javascriptdev
3
56