4 ms·
GCC Function Multiversioning
- wazari972 12y agoI wanted to give it a try, but if fails without considering the target attribute ... > gcc test.c -g > test.c:9:5: error: redefinition of ‘foo’ > int foo () > gcc version 4.9.2 (GCC) (archlinux)
- zimbu668 12y agoIt only works with c++, your command failed for me, try renaming the file: gcc test.cpp -g or use the c++ compiler explicitly: g++ test.c -g
- mineo 12y agoThat's because gcc is trying to compile it as C, not C++. You need to call the file "test.cpp" or explicitly use g++ instead of gcc to compile it. (You'll also need to "#include <assert.h>" or it won't compile.)
- nkurz 12y agoIt's not entirely clear, but I think this is a C++ only feature that is only available when using the GCC C++ front end (g++). The linked document includes the ambiguous "Support is only available in C++ for i386 targets", but other sources (such as the GCC 4.9.2 documentation) have clarified this to "With the GNU C++ front end, for target i386, you may specify multiple versions of a function". https://gcc.gnu.org/onlinedocs/gcc-4.9.2/gcc/Function-Multiversioning.html https://gcc.gnu.org/onlinedocs/gcc-4.9.2/gcc/Function-Multiv...
- wazari972 12y agoindeed, my bad! to my defense, the code looks a lot like C code ;-)
- deleted 12y ago[deleted]
- opk 12y agoLooks like gcc is also generating a dispatcher function. This should really be the runtime linker's job. Solaris has been able to do this for as long as I can remember.
- glandium 12y agoOne problem with doing it in the runtime linker is that the implementation needs to get it right to allow programs to run with a runtime linker that doesn't support it. And that would not work on e.g. Windows.