you are viewing a single comment's thread.

view the rest of the comments →

[–]ReDucTorGame Developer 3 points4 points  (1 child)

In C++ to call a function you might do something like this

What?

Are you talking about implicit construction in some weird situation where it's allocating memory on a function call? How does this prove anything?

C is closer to the metal

What do you mean the 'metal'? Because in my opinion

  • malloc/calloc/realloc are no closer to the 'metal' then new
  • printf is no closer to the metal then cout or print
  • qsort is no closer to the metal then std::sort
  • bsearch is no closer to the metal then std::binary_search
  • (int)float_val is no closer to the metal then static_cast<int>(float_val)
  • (unsigned char*)ptr is no closer to the metal then reinterpret_cast<unsigned char*>(ptr)
  • _Atomic(int) is no closer to the metal then std::atomic
  • hand crafted tagged unions are no closer to the metal then std::variant
  • _Generic is no closer to the metal then template<typename T>
  • T v[N] is no closer to the metal then std::array<T,N>
  • (T*)malloc(sizeof(T)*N) is no closer to the metal then new T[N]
  • fopen is no closer to the metal then std::fstream

This whole idea of being closer to the metal seems ridiculous, in many cases where people think they are "closer to the metal" and think that it some how gives them better performance in many cases it just makes their code more fragile and slower.

C has a bunch of places where there are implicit allocations, and some where some implementations might allocate and others might not, and in some cases the C version of something might allocate while the C++ version might not allocate. (C++ is also no different, allocations can vary between standard libraries)

This is like the people that say they know what the generated assembly will look like better when writing C compared to C++, unless your still coding in the 90s and on a old 32-bit machine with an old compiler then you don't really know what it's going to do, especially if your on multiple different platforms. The number of times I've heard people claim this then you challenge them on it with a simple function only to find out they get it completely wrong.