이입니다 밖으로 최적화 다소 예제 코드와 Casting a function pointer to another type에 대한 설명을 요청 대답은 "좋은"컴파일러는 에게 my_callback_helper()
기능을 최적화 할 수 있어야하지만, 내가 찾은 말한다도우미 기능을
struct my_struct;
void my_callback_function(struct my_struct* arg);
void do_stuff(void (*cb)(void*));
static void my_callback_helper(void* pv)
{
my_callback_function(pv);
}
int main()
{
do_stuff(&my_callback_helper);
}
https://gcc.godbolt.org IT 및 도우미 기능을 수행 에서 어떤 컴파일러는 항상 just a jump to my_callback_function()
(-03) 경우에도 생성되지 가져옵니다
my_callback_helper:
jmp my_callback_function
main:
subq $8, %rsp
movl $my_callback_helper, %edi
call do_stuff
xorl %eax, %eax
addq $8, %rsp
ret
제 질문은 : 컴파일러가 도우미를 제거하지 못하게하는 표준이 있습니까?
필자의 경험에 따르면, 컴파일러는 함수 포인터 값을 컴파일 타임에 결정할 수있는 경우에도 함수 포인터 호출을 인라이닝 할 때 성능이 좋지 않은 경향이 있습니다. 'inline' 키워드로 던져 볼 수도 있습니다. 내가 아는 한, 표준에는 최적화를 방해하는 요소는 없습니다. – Lundin