News for hackers. Stuff that matters.
Re:Modern C for C++ Peeps by detrites on Saturday January 07, 2023 @10:49AM (#34289119)
How is it hidden? Can't the inquiring mind simply examine the codebase to see it's a struct? And if they choose not to, isn't it on them if it turns out to be something other than what they assumed it was without looking?
Re:Modern C for C++ Peeps by moloch-hai on Saturday January 07, 2023 @11:03AM (#34289297)
It is hidden because you have to "examine" somewhere else before you know. But it doesn't matter, because you don't need to know unless it is subject to invisible implicit conversions. What might you do differently, having "examined" the typedef?
Re:Modern C for C++ Peeps by Warwolt on Saturday January 07, 2023 @11:36AM (#34289663)
I understand the preference for keeping the struct tag, but virtually no other language does this, with modern IDEs it's trivial to find out what the definition of a given type is, so the tag seems superfluous to me in practice.
Re:Modern C for C++ Peeps by Jtsummers on Saturday January 07, 2023 @11:41AM (#34289714)
* * *
Re:Modern C for C++ Peeps by rm445 on Saturday January 07, 2023 @02:04PM (#34291402)
I think so. Even with a compiled library distributed with a header file but no source, the header file needs to forward declare something like 'typedef struct foo FOO;' So (unless there's some clever trick I've missed) you can always tell it's a struct but not necessarily see the definition.

There is a point, perhaps a little specious, that you put a module's data structures behind a typedef so the interface doesn't change if it changes from a simple data type to a struct. Probably doesn't happen too often.

The perfect C object-oriented-style interface is FILE* from stdio.h. A FILE is a structure full of operating-system-specific file information but you never have to see it or worry about what's in it, you just use the functions.

Re:Modern C for C++ Peeps by heywhatupboys on Saturday January 07, 2023 @04:43PM (#34293180)
> There is a point, perhaps a little specious, that you put a module's data structures behind a typedef so the interface doesn't change if it changes from a simple data type to a struct. Probably doesn't happen too often.

you could never do this in C. If it is a "value type" i.e. a non-pointer, then you cannot change the size of the value, without changing the ABI and the function decl.