TomHarte / CLK

A latency-hating emulator of: the Acorn Electron and Archimedes, Amstrad CPC, Apple II/II+/IIe and early Macintosh, Atari 2600 and ST, ColecoVision, Enterprise 64/128, Commodore Vic-20 and Amiga, MSX 1/2, Oric 1/Atmos, early PC compatibles, Sega Master System, Sinclair ZX80/81 and ZX Spectrum.
MIT License
911 stars 50 forks source link

Add missing include of cstring for memcpy. #1322

Closed ryandesign closed 5 months ago

ryandesign commented 5 months ago

In the new CMake build system I'm putting together for Clock Signal, I pretty much included all the source files. This built fine on macOS 12 using Apple clang 14.0.0 but on Linux Mint 21.2 with g++ 11.4.0 it failed:

/home/rschmidt/repos/CLK/Processors/AllRAMProcessor.cpp: In member function ‘void CPU::AllRAMProcessor::set_data_at_address(size_t, std::size_t, const uint8_t*)’:
/home/rschmidt/repos/CLK/Processors/AllRAMProcessor.cpp:20:9: error: ‘memcpy’ was not declared in this scope
   20 |         memcpy(&memory_[start_address], data, end_address - start_address);
      |         ^~~~~~
/home/rschmidt/repos/CLK/Processors/AllRAMProcessor.cpp:10:1: note: ‘memcpy’ is defined in header ‘<cstring>’; did you forget to ‘#include <cstring>’?
    9 | #include "AllRAMProcessor.hpp"
  +++ |+#include <cstring>
   10 | 
/home/rschmidt/repos/CLK/Processors/AllRAMProcessor.cpp: In member function ‘void CPU::AllRAMProcessor::get_data_at_address(size_t, std::size_t, uint8_t*)’:
/home/rschmidt/repos/CLK/Processors/AllRAMProcessor.cpp:25:9: error: ‘memcpy’ was not declared in this scope
   25 |         memcpy(data, &memory_[start_address], end_address - start_address);
      |         ^~~~~~
/home/rschmidt/repos/CLK/Processors/AllRAMProcessor.cpp:25:9: note: ‘memcpy’ is defined in header ‘<cstring>’; did you forget to ‘#include <cstring>’?
make[2]: *** [CMakeFiles/clksignal.dir/build.make:2277: CMakeFiles/clksignal.dir/Processors/AllRAMProcessor.cpp.o] Error 1

This PR fixes it by including <cstring> as suggested.

I realize now that the SCons build didn't have this problem because it doesn't include AllRAMProcessor.cpp so I guess it isn't needed to build the program…

TomHarte commented 5 months ago

Oh, yeah, those AllRAMProcessors are more like documentation than anything else, though they're used in part by test cases.

Regardless, thanks!