Hrm. C++ supports implicit conversion operators.

So, why the hell doesn’t std::string have one for const char *? That’d eliminate the use of .c_str() when talking to libc and other C libraries, outside of variadic parameters.

@gudenau Perhaps. Also makes it stupidly easy to have what looks like a C-style cast turn into the implicit invocation of an arbitrary amount of code. One of those “use with care” features.

@SuperFloppies Hmm, would be interesting if there was an operator like ((cast)) instead of (cast) to enable "expensive" casts.

@gudenau ... or a compiler flag to disable implicit conversions. Hrm. Time to look at the compiler manual again...

@SuperFloppies That one would be a little more global, I was thinking a different operator so you can use it sometimes when it is intended.

@SuperFloppies Oh, another thing I wanted to ask you about C++. Can you use that "goes out of scope" operator thing? Don't know the details off the top of my head but I remember it in a Vulkan guide.

@SuperFloppies There was some thing that called cleanup stuff when variables went out of scope. Like a local var would have the cleanup called when the function returned and Objects would have them cleaned up automatically when it was deleted without using the deconstructor.

@SuperFloppies Kind of like `java.lang.ref.Cleaner` but on scope changes not on garbage collection.

@gudenau Hrm. You can enable -Wold-style-cast -Werror, which forces you to use the newer C++ casts instead. Seems to be the only way, short of not defining implicit conversion operators.

Sign in to participate in the conversation
Mastodon for Tech Folks

This Mastodon instance is for people interested in technology. Discussions aren't limited to technology, because tech folks shouldn't be limited to technology either!

We adhere to an adapted version of the TootCat Code of Conduct and follow the Toot Café list of blocked instances. Ash is the admin and is supported by Fuzzface as a moderator.

Hosting costs are largely covered by our generous supporters on Patreon – thanks for all the help!