Processor: Intel Xeon E3-1230 v2
OS: Win 7 64bit
Compiler: GCC
The code is shown below:
#include <stdio.h>
int atomic_add_int(volatile int * address, int value){
asm volatile ("lock xadd %0, %1" : <-- line 11
"+r" (value) :
"+m" (*address) :
"memory");
return value;
}
int atomic_inc_int(int * address){
asm volatile("lock inc %0": : <-- line 21
"+m" (*address):
"memory");
return (*address);
}
int main(){
}
When I compile the code(>gcc -c sample.c), the errors occur:
sample.c: In function 'atomic_add_int':
sample.c:14:3: error: input operand constraint contains '+'
sample.c: In function 'atomic_inc_int':
sample.c:23:3: error: input operand constraint contains '+'
sample.c:21:2: error: input operand constraint contains '+'
sample.c: In function 'atomic_add_int':
sample.c:11:2: error: input operand constraint contains '+'
I wrote the code as the book(Multicore Application Programming) tell me to, but why those error occur? Can any one help me? Thanks.