Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I just found another way to replace the <code>memcpy</code> function call. It only works with GCC(I still need to find another way for VC++) but I think it's definitely better than the crude <code>#define</code> way. It uses the <code>__REDIRECT</code> macro(in <code>sys/cdefs.h</code> included via <code>features.h</code>), which from what I've seen it's used extensively in the glibc. Below follows an example with a small test:</p> <pre><code>// modified.h #pragma once #ifndef MODIF_H_INCLUDED_ #define MODIF_H_INCLUDED_ #include &lt;cstddef&gt; #include &lt;features.h&gt; extern "C" { void test_memcpy(void* __restrict to, const void* __restrict from, size_t size); } #if defined(__GNUC__) void __REDIRECT(memcpy, (void* __restrict to, const void* __restrict from, size_t size), test_memcpy); #endif /* __GNUC__ */ #endif /* MODIF_H_INCLUDED_ */ //modified.cpp extern "C" void test_memcpy(void* __restrict to, const void* __restrict from, size_t size) { std::cout &lt;&lt; "Dumb memcpy replacement!\n"; } //original.h #pragma once #ifndef ORIG_H_INCLUDED_ #define ORIG_H_INCLUDED_ void test_with_orig(); #endif /* ORIG_H_INCLUDED_ */ //original.cpp #include &lt;cstring&gt; #include &lt;iostream&gt; void test_with_orig() { int* testDest = new int[10]; int* testSrc = new int[10]; for (unsigned int i = 0; i &lt; 10; ++i) { testSrc[i] = i; } memcpy(testDest, testSrc, 10 * sizeof(int)); for (unsigned int i = 0; i &lt; 10; ++i) { std::cout &lt;&lt; std::hex &lt;&lt; "\nAfter standard memcpy - " &lt;&lt; "Source: " &lt;&lt; testSrc[i] &lt;&lt; "\tDest: " &lt;&lt; testDest[i] &lt;&lt; "\n"; } } // and a small test #include "modified.h" #include "original.h" #include &lt;iostream&gt; #include &lt;cstring&gt; int main() { int* testDest = new int[10]; int* testSrc = new int[10]; for (unsigned int i = 0; i &lt; 10; ++i) { testSrc[i] = i; testDest[i] = 0xDEADBEEF; } memcpy(testDest, testSrc, 10 * sizeof(int)); for (unsigned int i = 0; i &lt; 10; ++i) { std::cout &lt;&lt; std::hex &lt;&lt; "\nAfter memcpy replacement - " &lt;&lt; "Source: " &lt;&lt; testSrc[i] &lt;&lt; "\tDest: " &lt;&lt; testDest[i] &lt;&lt; "\n"; } test_with_orig(); return 0; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload