r/ProgrammerHumor • • Jan 28 '23

Meme C++

Post image
53.9k Upvotes

1.5k comments sorted by

View all comments

Show parent comments

2

u/[deleted] Jan 28 '23 edited Jan 28 '23

In all technicality, structures are simply for convenience. Nothing is stopping anyone from extracting parts of a data buffer or building a data buffer with the same layout as a structure in a native API. I do not see this very often outside of embedded development however and isn't a practice I really support either, makes things a tad bit less readable.

In a recent C# project of mine I didn't use structs and instead built a buffer from scratch to throw at Win32. Just about any project I do with interop and FAMs I don't even define any structs, I build buffers manually because it's so much easier to do. Readability is shit, but it beats having to create a custom marshaller each and every time. If anyone has a better solution I am all ears!