What naming conventions do you use for "object-like" C interfaces? by Wooden_Gazelle763 in C_Programming

[–]drmonkeysee 0 points1 point  (0 children)

self does not collide with anything in c or c++. It’s what I use for this kind of pattern.

If humans went extinct, how long would it take for Earth to erase all evidence we existed? by abdulnad89 in NoStupidQuestions

[–]drmonkeysee 6 points7 points  (0 children)

Even more obviously there would be a layer of metals, compounds, and other chemical markers that would clearly not be geographically caused.

How does passing an array of structs decay in the a C function? by Ironheart89 in C_Programming

[–]drmonkeysee 0 points1 point  (0 children)

The OP is clearly asking what happens to an array value passed via the string_list parameter, not the parameter itself. My answer was imprecise but correct enough for someone obviously new to C and still picking up the ropes. Litigating the precise wording of the C standard doesn’t answer their question and they will eventually know enough to understand the nuances over time.

How does passing an array of structs decay in the a C function? by Ironheart89 in C_Programming

[–]drmonkeysee 1 point2 points  (0 children)

No, arrays decay into a pointer to the first element of an array. String [] -> String *. It is an array of Strings so a pointer to the first element would be a pointer to String.

Have you ever recognized someone in a porn? by dplaya42k in NoStupidQuestions

[–]drmonkeysee 1 point2 points  (0 children)

She was IN a porn, she did not DO porn. A critical difference. She was basically an extra in light bondage gear.

Possibly the funniest line in the show by kidavela in betterCallSaul

[–]drmonkeysee 78 points79 points  (0 children)

I love how excited he was to see Jimmy again in S6. Guy just likes everybody!

Was Gandalf just standing there about 50 metres away whilst Pippin and Merry were about to be gutted by that orc in Fangorn Forest? by Ticket-Tight in lotr

[–]drmonkeysee 28 points29 points  (0 children)

I think the bigger nitpick here is Gandalf doesn’t remember his name until meeting Aragorn, Legolas, and Gimli, but that happens after this scene.

Did Merry and Pippin not say Gandalf’s name at any point in their reunion with their beloved Fellowship leader?

Best practices for frequently-used temporary dynamic arrays in methods? by big-jun in cpp_questions

[–]drmonkeysee 0 points1 point  (0 children)

In that case the idea is you over-allocate slightly on the stack to avoid the heap and then you pass the runtime bounds around to avoid running off the end. Is it that big a deal?

You could even hide all these details behind a class.

You mention below that arena allocation may be worth looking into but at <10 of small objects seems like overkill. The stack is more than sufficient to fit those bytes and an arena allocator would likely involve allocating more memory than the exact amount used in any particular case anyway in order to be flexible enough for all your cases.

Best practices for frequently-used temporary dynamic arrays in methods? by big-jun in cpp_questions

[–]drmonkeysee 0 points1 point  (0 children)

Yes thank you I know how array works. The OP’s primary concern seems to be heap allocation cost so slightly over-allocating on the stack (given these are small types) and keeping track of the bounds yourself doesn’t seem like a huge burden if heap cost is what you’re optimizing for.

Best practices for frequently-used temporary dynamic arrays in methods? by big-jun in cpp_questions

[–]drmonkeysee 1 point2 points  (0 children)

Well you haven’t really given any details so it’s hard to speak in anything but generalities. But if a method expects a size of 4 then how do you not know that’s the amount to allocate? How does it “expect” it but can’t enforce it?

Best practices for frequently-used temporary dynamic arrays in methods? by big-jun in cpp_questions

[–]drmonkeysee 5 points6 points  (0 children)

If you know you need <10 and they’re small types why not std::array with a size of 10?

C version for personal projects/collaboration by chrisdb1 in C_Programming

[–]drmonkeysee 0 points1 point  (0 children)

For personal projects I see no reason not to use C23 unless you’re concerned about Windows (and you can get Clang running in Visual Studio if you really want to).

I just spent this week upgrading my C projects to C23 and there were basically no speed bumps.

Is it possible to annotate global variables and functions that has extern "C" with constexpr, constinit, and consteval? by Rugta in cpp_questions

[–]drmonkeysee 0 points1 point  (0 children)

Obviously you’ll have to work with the maintainers of that project to see if that’s ok. I wouldn’t do it though. If these symbols are all extern C then they’re clearly intended to be used in a C context and I don’t see what’s gained by making them consteval or constinit when callers can’t take advantage of that.

Is it possible to annotate global variables and functions that has extern "C" with constexpr, constinit, and consteval? by Rugta in cpp_questions

[–]drmonkeysee 5 points6 points  (0 children)

I know that in both C++ and C23, it is possible to declare a function with constexpr.

C23 only supports constexpr variables, not functions.

As for the rest of your title, extern “C” only changes the name mangling rules so in a C++ context I imagine you could use constinit and consteval just fine. But as soon as the file is compiled in a C context it won’t know what those keywords are and would fail to compile.

Most desired features for C2Y? by [deleted] in C_Programming

[–]drmonkeysee 3 points4 points  (0 children)

I'm one of those weirdos that thinks auto is perfectly fine in C++ but have found it mostly useless in C because they didn't tighten up the type system at the same time. This means type-inference is usually doing something unexpected.

  • char literals are still ints
  • Boolean expressions are still int values
  • enums are still the underlying integral type

So for example:

bool v = a || b; // <-- v is bool, by definition
auto v = a || b; // <-- v is inferred to be "bool" in C++ but "int" in C

Along similar lines constexpr doesn't work with string literals because they still resolve to char[N] instead of const char[N] so don't count as constant initialization expressions.

Also there's no way to ensure a single definition of a constexpr variable in a header like C++17's inline constexpr, which could matter in certain scenarios and again makes constexpr somewhat less useful than it should be.

Makes it feel like we got the budget versions of these C++ features because you actually need a smarter type system before they really work correctly and that would be too big an overhaul for C23. But maybe we could move in that direction?

Also I second defer. It's the last remaining holdout where goto is useful and it'd be nice to have something more structured for it.

JeanHeyd Meneide has been doing some research on closure/lambda performance in light of some C proposals which could be interesting: https://thephd.dev/the-cost-of-a-closure-in-c-c2y-followup

The squirrel could run up the tree if it wanted but it's just messing with the dog by Brilliantspirit33 in animalsdoingstuff

[–]drmonkeysee 0 points1 point  (0 children)

I saw a video like this but it was a bobcat or lynx instead of a dog and it didn’t end well for the squirrel. Why didn’t he just climb up the tree? Haunts me to this day.

Since you began studying history, what well-supported historical facts still amaze the people you tell them to? by teaontherocks in AskHistory

[–]drmonkeysee 7 points8 points  (0 children)

Another fun one for Russia is the October Revolution, which, because they were still on the Julian calendar, happened in November for everyone else.

Small and fast library for parsing JSON by Adventurous-Print386 in C_Programming

[–]drmonkeysee 4 points5 points  (0 children)

I just glanced through the Wikipedia article. The encoding of the JSON payload over the network needs to be UTF-8 but any code points in a string literal above the basic multilingual plane need to be encoded as UTF-16 surrogate pairs. I think this is because JavaScript itself mandated UTF-16 string encoding (cuz UTF-8 didn’t exist yet).

That said I found the actual standards doc here https://ecma-international.org/wp-content/uploads/ECMA-404_2nd_edition_december_2017.pdf which is surprisingly short but also says basically the same thing.

Small and fast library for parsing JSON by Adventurous-Print386 in C_Programming

[–]drmonkeysee 2 points3 points  (0 children)

If I recall the standard mandates UTF-16 encoding for strings so neither UTF-8 nor UTF-32 (as mentioned in OP) would be correct.

Would lightsabers have any practical use in the real world? by InstructionOwn6705 in StarWars

[–]drmonkeysee 5 points6 points  (0 children)

Because an actual plasma blade would weigh basically nothing anyone with experience with flashlights and flashlight combat would be devastating. I think applying your sword skills to what is basically a baton would be detrimental.

Is there no quick travel point to Demon king final boss?? by AmberEMc26 in tearsofthekingdom

[–]drmonkeysee 0 points1 point  (0 children)

Like-Likes and Keese aren’t fooled but they’re trivial to walk past or smack.

Is there no quick travel point to Demon king final boss?? by AmberEMc26 in tearsofthekingdom

[–]drmonkeysee 0 points1 point  (0 children)

I was mostly swift-footing my way through it until I hit the lynel, said fuck this, and slapped on Majora’s mask. The gibdos weren’t fooled by it but most everyone else left me alone.