I think that these could be turned into structs that wrap the uintptr_t
, although that might have performance effects (it shouldn’t, but I don’t know how good the various C compiler optimizers are). I tried making this change for term_t
, but it looked as if it would be quite a bit of work. If you think that this is worthwhile, then let’s start a separate thread to discuss it.
I ran into a strange implicit conversion error between int
and char*
, and rather than figure out what was going on, I just added tags to all the C types (but not to C++ types such as PlAtom
). Possibly this was too strict – I can try removing the tags for char*
and see if it still works. (The weirdest implicit conversion I found was when term_t
(or maybe atom_t
) was converted to float! … I didn’t figure out how that happened …)
The only reason for not using std::string
everywhere is that it involves an extra copy operation. char*
is one of those weird left-overs from C that’s used everywhere, so for now, I’d prefer leaving std::string
out as the default and instead of c_str()
as the standard. (Some of the copying can be avoided by using “move constructors”, but that’s a fairly new feature that I don’t fully understand, so I don’t want to use it – yet).
[Note that std::string::c_str()
may also require a copy.]
[There’s also std::wstring
, which is defined as basic_string<wchar_t>
… that could be used to replace my get_wchar_t()
]
[As far as I know, cout << "Hello" << endl
passes a char*
to the stream and doesn’t use a default constructor for std::string
(which would - probably - require a string copy of some kind). I might be wrong, but I don’t know how to verify this. If it matters, I know a few people working on C++ compilers and I could ask one of them.]
In general everything that accepts a char*
should also accept a std::string
, to avoid copying overheads. See also: abseil / Strings Library
You mean: remove the “get_” prefix? That seems fine, but I suppose we would still need A1.get_type_t()
. I can leave the conversion operator in (it’s currently “deprecated”), but that results in the somewhat ungainly static_const<term_t>(A1)
… the C-style (term_t)A1
is allowed by is considered bad style; however, I just learned about the “{}” form in C++, so term_t{A1}
can be used, and I can un-deprecate the term_t
conversion operator … should I also un-deprecate the other conversion operators and get rid of the “get_XXX” forms? (or maybe allow both)
Good to know … I’ll change some of my tests. This will delay my changes to SWI-cpp.h being submitted (I’m adding tests to both the existing test_ffi.c
and to the new test_cpp.c
).
EDITED: added some clarification about char*
and std::string
.