r/C_Programming • u/Gullible_Ostrich_370 • Jul 17 '26
C with classes
I'm curious to know: who uses some C++ features when coding in C? And what feature(s) are you using?
29
Upvotes
r/C_Programming • u/Gullible_Ostrich_370 • Jul 17 '26
I'm curious to know: who uses some C++ features when coding in C? And what feature(s) are you using?
View all comments
Show parent comment
1
u/Bros2316 Jul 18 '26
I think it’s all dependent on the application of your program and what you’re trying to accomplish. For example, let’s assume that you have a static buffer that is 100 bytes. Let’s say all that entries are prepended with their length.
This buffer contains two “strings”, a hash, and some numbers that need referenced.
An array may work for some, but not all data types in this case. So you could have a parse function that parses this buffer and returns slices of the types of data and their lengths that you are wanting to extract. Returning slices now removes the need to dynamically allocate anything in this case as you’re just creating fat pointers that are strictly const references.