Re:The C Programming Language: Myths and Reality (1)
by gjulianm on Monday July 17, 2023 @10:25AM
(#36758604)
Yes, that's usually how it goes, each header/source is like a "class". And usually, what you have is a "main" struct that represents the "class" itself. In this case that main struct can't have both private and public fields.
[ Parent
| on HN ]
Re:The C Programming Language: Myths and Reality (1)
by falcrist on Monday July 17, 2023 @10:37AM
(#36758773)
> And usually, what you have is a "main" struct that represents the "class" itself.
Yes that tracks with the work I've done. It could even be so simple that only one value needs to be exposed through a getter (along with a couple "methods").
An ADC in an embedded system could operate like that.
Re:The C Programming Language: Myths and Reality (1)
by lelanthran on Monday July 17, 2023 @11:55AM
(#36759757)
> Yes, that's usually how it goes, each header/source is like a "class". And usually, what you have is a "main" struct that represents the "class" itself. In this case that main struct can't have both private and public fields.
You can, in a defined way (i.e., no invoking of UB). I just didn't put that in.
Re:The C Programming Language: Myths and Reality (1)
by gjulianm on Monday July 17, 2023 @03:21PM
(#36762724)
Out of curiosity, how would you do it? The ways I've seen require using another "public" struct and either casting public to private or using a nested pointer, each with their set of problems. In either case, it's still a bit hacky and still each struct is all-or-nothing public or private.
Re:The C Programming Language: Myths and Reality (1)
by lelanthran on Monday July 17, 2023 @04:10PM
(#36763371)
Pretty much. All the casting and hackiness isn't visible to the caller, and the implementation still maintains its ABI when the private stuff changes.