diff --git a/include/efp/cpp_core.hpp b/include/efp/cpp_core.hpp index c2936c2..ec05c28 100644 --- a/include/efp/cpp_core.hpp +++ b/include/efp/cpp_core.hpp @@ -20,15 +20,22 @@ #include namespace efp { -void* (*memcpy)(void* dest, const void* src, size_t size) = std::memcpy; +// Use a function alias for clarity and avoid direct assignment to avoid potential confusion. +inline void* _memcpy(void* dest, const void* src, size_t size) { + return std::memcpy(dest, src, size); } +} // namespace efp #else namespace efp { -void* memcpy(void* dest, const void* src, size_t size) { +// Custom memcpy implementation for freestanding environments. +// Added extern "C" to ensure C linkage for compatibility with C libraries or code. +extern "C" void* _memcpy(void* dest, const void* src, size_t size) { + auto* d = static_cast(dest); + const auto* s = static_cast(src); for (size_t i = 0; i < size; ++i) { - static_cast(dest)[i] = static_cast(src)[i]; + d[i] = s[i]; } return dest; } diff --git a/include/efp/string.hpp b/include/efp/string.hpp index a0a3c41..984a004 100644 --- a/include/efp/string.hpp +++ b/include/efp/string.hpp @@ -31,14 +31,14 @@ class Vector::value>> Base::_size = Traits::length(c_str); Base::_capacity = Base::_size + 1; Base::_data = Base::_allocator.allocate(Base::_capacity); - efp::memcpy(Base::_data, c_str, Base::_size * sizeof(Char)); + _memcpy(Base::_data, c_str, Base::_size * sizeof(Char)); } Vector(const Char* s, size_t count, const Allocator& alloc = Allocator()) { Base::_size = count; Base::_capacity = Base::_size + 1; Base::_data = Base::_allocator.allocate(Base::_capacity); - efp::memcpy(Base::_data, s, Base::_size * sizeof(Char)); + _memcpy(Base::_data, s, Base::_size * sizeof(Char)); } Vector(size_t size, Char c) { @@ -220,7 +220,7 @@ class Vector::value>> count = Base::_size - pos; } - efp::memcpy(dest, Base::_data + pos, count * sizeof(Char)); + _memcpy(dest, Base::_data + pos, count * sizeof(Char)); return count; }