()
), will put, literally, { ; }
wherever you call that macro. That code does nothing. It's not even a no-op, it will not actually add assembly code to the binary. Take this example:#include <stdio.h>
#define IDLE_WORK() { ; }
void main(){
printf("start\n");
IDLE_WORK();
printf("end\n");
}
main:
.LFB0:
.file 1 "noop_test.c"
.loc 1 6 12
.cfi_startproc
pushq %rbp #
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp #,
.cfi_def_cfa_register 6
# noop_test.c:7: printf("start\n");
.loc 1 7 2
movl $.LC0, %edi #,
call puts #
# noop_test.c:9: printf("end\n");
.loc 1 9 2
movl $.LC1, %edi #,
call puts #
# noop_test.c:10: }
.loc 1 10 1
nop
popq %rbp #
.cfi_def_cfa 7, 8
ret
.cfi_endproc
printf
s are the same and there are no extra instructions generated between them for the macro.#define MY_AWESOME_BLOCK() do { /* CODE HERE */ } while(0)
if (1 == 0){
printf("physics exploded\n");
} else MY_AWESOME_BLOCK();
else
block and the rest would be one level up, which is most certainly not the intent. Macros are messy. Tread carefully.Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.