* Clobbering memory region
@ 2007-12-08 17:20 Udo A. Steinberg
0 siblings, 0 replies; only message in thread
From: Udo A. Steinberg @ 2007-12-08 17:20 UTC (permalink / raw)
To: gcc-help
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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2007-12-08 17:20 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-12-08 17:20 Clobbering memory region Udo A. Steinberg
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).