Question:
What's the difference between:
int fun(int ()) {
return 1;
}
and
int fun(int (*)()) {
return 1;
}
Answer:
You can check for yourself if there is a difference and what it is with the help of: the compiler and nm
. When you try to compile a program (or lib) with both definitions in the same namespace
, you will get an error about redefining the function. If you compile first with the first, and then with the second option and see what happens in the end with nm
, then you will see the following picture (without mangling):
0000000000004028 B __bss_start
0000000000004028 b completed.7325
w __cxa_finalize@@GLIBC_2.2.5
0000000000004018 D __data_start
0000000000004018 W data_start
0000000000001070 t deregister_tm_clones
00000000000010e0 t __do_global_dtors_aux
0000000000003df0 t __do_global_dtors_aux_fini_array_entry
0000000000004020 D __dso_handle
0000000000003df8 d _DYNAMIC
0000000000004028 D _edata
0000000000004030 B _end
00000000000011a4 T _fini
0000000000001120 t frame_dummy
0000000000003de8 t __frame_dummy_init_array_entry
000000000000216c r __FRAME_END__
0000000000004000 d _GLOBAL_OFFSET_TABLE_
w __gmon_start__
0000000000002004 r __GNU_EH_FRAME_HDR
0000000000001000 t _init
0000000000003df0 t __init_array_end
0000000000003de8 t __init_array_start
0000000000002000 R _IO_stdin_used
w _ITM_deregisterTMCloneTable
w _ITM_registerTMCloneTable
00000000000011a0 T __libc_csu_fini
0000000000001140 T __libc_csu_init
U __libc_start_main@@GLIBC_2.2.5
0000000000001134 T main
00000000000010a0 t register_tm_clones
0000000000001040 T _start
0000000000004028 D __TMC_END__
0000000000001125 T fun(int (*)())
0000000000004028 B __bss_start
0000000000004028 b completed.7325
w __cxa_finalize@@GLIBC_2.2.5
0000000000004018 D __data_start
0000000000004018 W data_start
0000000000001070 t deregister_tm_clones
00000000000010e0 t __do_global_dtors_aux
0000000000003df0 t __do_global_dtors_aux_fini_array_entry
0000000000004020 D __dso_handle
0000000000003df8 d _DYNAMIC
0000000000004028 D _edata
0000000000004030 B _end
00000000000011a4 T _fini
0000000000001120 t frame_dummy
0000000000003de8 t __frame_dummy_init_array_entry
000000000000216c r __FRAME_END__
0000000000004000 d _GLOBAL_OFFSET_TABLE_
w __gmon_start__
0000000000002004 r __GNU_EH_FRAME_HDR
0000000000001000 t _init
0000000000003df0 t __init_array_end
0000000000003de8 t __init_array_start
0000000000002000 R _IO_stdin_used
w _ITM_deregisterTMCloneTable
w _ITM_registerTMCloneTable
00000000000011a0 T __libc_csu_fini
0000000000001140 T __libc_csu_init
U __libc_start_main@@GLIBC_2.2.5
0000000000001134 T main
00000000000010a0 t register_tm_clones
0000000000001040 T _start
0000000000004028 D __TMC_END__
0000000000001125 T fun(int (*)())
Tobish the first option and the second one are just two versions of the same entry