Clobbering memory region

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux