B
BGB
Rightly so. C has things call functions that enable code to be reused
and C++ has function templates that remove the last excuse for copy and
paste.
Not if they were being paid to deliver software.
well, if they just copy/paste it from existing sources, they may be
stuck with GPL nastiness or similar (since, annoyingly, the majority of
existing/FOSS source is GPL), so writing it initially will give them a
version for which they control the license (while still being legal, and
not simply "forgetting" the per-existing license terms).
for example, I have ended up having to write pretty much a whole damn 3D
engine to get away from the GPL and stay reasonably close to familiar
territory (my plans are to use the MIT license for most of the core).
recently I have (at least experimentally) loaded up Doom3 maps in my own
engine, however for the most part I have previously been using
Quake-style maps (mostly from Quake 1). I had also loaded up maps from
Xonotic (sort of like a Quake-3 Arena clone based on a heavily modified
Quake-1 engine, namely DarkPlaces).
Most C++ code passes strings by const reference.
I guess people do both.
I had seen references to it apparently being a style debate between
using references and passing them by value, with different performance
tradeoffs existing between compilers.
With some compilers in some modes, passing a string by value will be
quicker if the string object (typically a pair of pointers) is small
enough to pass in registers.
dunno, it depends on the compiler.
the version of the object I am familiar with happens to contain (IIRC) a
reference count, a maximum size (capacity), a length field, and a
character array aliased against a pointer.
In other words, wrapping them like std::string...
yep, except that this also works with plain C (relevant since the
project is largely mixed-language, and C-style is the only thing
"everyone" understands).
actually, it is more restricted than this, typically not only do they
have to be plain C types but also visible to the garbage collector and
to the VM type-system.
technically, the pointer values are equivalent, but different functions
are used to return either "char *" or "dyt" (a magic type used for
dynamically typed objects), mostly to avoid the need for manual casting
or the compiler throwing a fit due to implicit pointer-type conversions.
trivia:
there are overloaded operators so that "dyt" behaves more like a
built-in type in C++, whereas one needs things like "dyadd(a, b)" in C.
for many shared-language constructs, it is usually least effort to make
them behave C-like internally, and give optional overloaded operators or
wrapper classes for the C++ case.
in a few cases, the methods actually just redirect, either to calling
through a function-pointer (for C and C++ code to implement the real
logic), or redirecting the call into the scripting VM (such as if a
VM-managed object is placed into a field, such as "dy_this").
say, for example:
void FooObject::fooMethod()
{
if(dy_this)
{
dyCallSigv(dy_this, "fooMethod", "()v");
return;
}
if(vtable->fooMethof_f)
vtable->fooMethof_f();
}
it can all get kind of hairy at times, but it works...
Or save a whole lot of pain and use std::string.
except, as noted above, I can't do this generally, as C++ is only used
in parts of the project.
granted, std::string makes a lot more sense for a pure-C++ project (or
at least a "strongly dominantly C++" project).