What exactly is an object?
What exactly is an object?
Posted Feb 24, 2025 17:06 UTC (Mon) by dmv (subscriber, #168800)Parent article: Slabs, sheaves, and barns
Posted Feb 24, 2025 17:10 UTC (Mon)
by corbet (editor, #1)
[Link] (5 responses)
Sorry if that wasn't clear.
Posted Feb 24, 2025 17:15 UTC (Mon)
by dmv (subscriber, #168800)
[Link]
Posted Feb 24, 2025 22:18 UTC (Mon)
by tialaramex (subscriber, #21167)
[Link] (3 responses)
What's weird is that C++ and Java for some reason give methods to some things but not others. There's no particular reason 'x'.is_lowercase() shouldn't work, which is why it does in Rust, there's no real "extra" work to deliver this compared with my_goose.honk() in both cases the compiler just has to figure out what type the object is and then go find the function to call (a "method") based on that type then fill in that object as a parameter to the function. In 1972 in a few hundred kilobytes of RAM I can well believe that's an unaffordable luxury for Dennis and so its absence from C is not a great surprise, but why implement this and then switch it off for the built-in types in a newer language? Search me.
While writing this comment and looking at the Rust docs for Kmalloc I found a doc bug - for a conventional Rust crate I'm pretty clear about how I can report or fix this. But it's not as obvious to me for the kernel code - please tell me I don't need to brave the LKML Jonathan?
The text "if `old_layout` is zero-sized `p` does not need to be a pointer returned by this [`Allocator`]." is unnecessary for free() as we do not provide an old_layout parameter. I can't tell (but hopefully the authors know) whether it is appropriate to simply remove this text, or whether in addition some other text should be provided about zero-size things being freed, or not freed as the case may be.
Posted Feb 25, 2025 10:11 UTC (Tue)
by Sesse (subscriber, #53779)
[Link] (2 responses)
Of course, adding _data members_ to another class from the outside would be nearly impossible in C++'s compilation model (which it, of course, inherited from C).
Posted Feb 25, 2025 20:09 UTC (Tue)
by tialaramex (subscriber, #21167)
[Link] (1 responses)
C++ ADL which maybe you were also gesturing at is just a mess. Your whatever function is indeed treated by C++ as if it's "part of Foo's interface" but only when it was defined in the same namespace so that ADL will find whatever when it is looking up Foo. This causes weird hard to understand issues in real world C++ software because what foo(bar) means will depend on the context in which you wrote it in non-obvious ways, as a result "turning off ADL" via arcane tricks is often needed & there have been attempts to reform ADL or to add explicit "No ADL please" features to the language.
I was serious about that docbug, who do I raise this with? I'd rather raise it as a bug rather than sending a patch because I'm certain those answering the bug ticket will know more than I do about kmalloc
Posted Feb 27, 2025 9:28 UTC (Thu)
by aviallon (subscriber, #157205)
[Link]
Posted Feb 25, 2025 16:01 UTC (Tue)
by rweikusat2 (subscriber, #117920)
[Link]
An "object" is just a piece of memory, yes. No methods or other class-like stuff, this is C we're talking about :)
What exactly is an object?
What exactly is an object?
What exactly is an object?
What exactly is an object?
What exactly is an object?
What exactly is an object?
What exactly is an object?
