This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]