This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Clobbering memory region
- From: "Udo A. Steinberg" <us15 at os dot inf dot tu-dresden dot de>
- To: gcc-help at gcc dot gnu dot org
- Date: Sat, 8 Dec 2007 18:20:19 +0100
- Subject: Clobbering memory region
Hello all,
An easy way to specify that an inline assembler statement changes memory is
to add "memory" to the clobber list. However, that is overly pessimistic.
As an alternative one can specify an output parameter for the memory region
like this:
#include <stddef.h>
void *memcpy (void *d, void const *s, size_t n)
{
unsigned dummy;
asm volatile ("rep; movsb"
: "=D" (dummy), "+S" (s), "+c" (n),
"=m" (*(struct { char x[n]; } *) d)
: "0" (d));
return d;
}
This works well in C (e.g., via gcc -c test.c).
With C++ (g++ -c test.c) the compiler complains:
test.c: In function 'void* memcpy(void*, const void*, size_t)':
test.c:9: error: types may not be defined in casts
test.c:9: error: array bound is not an integer constant
Is there a way to make this kind of sophisticated clobber work in C++ also?
Cheers,
- Udo