From: Alexei Sheplyakov Date: Wed, 6 Jan 2010 17:55:43 +0000 (+0200) Subject: Use C style cast when converting void* into function pointer. X-Git-Tag: release_1-5-6~1 X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=commitdiff_plain;h=352547eac1ff77d754870b3b8299899089edc24b Use C style cast when converting void* into function pointer. Building GiNaC 1.5.5 with GCC 3.4 fails with the following error: libtool: compile: ccache g++-3.4 -DHAVE_CONFIG_H -I. -I../../ginac -I../config -I/home/pc7135/varg/target/x86_64-linux-gnu/include -O2 -g -Wall -pipe -MT builtin_fcns.lo -MD -MP -MF .deps/builtin_fcns.Tpo -c ../../ginac/parser/builtin_fcns.cpp -fPIC -DPIC -o .libs/builtin_fcns.o ../../ginac/parser/builtin_fcns.cpp: In function `GiNaC::ex (* GiNaC::encode_serial_as_reader_func(unsigned int))(const GiNaC::exvector&)': /home/pc7135/varg/tmp/build/GiNaC/build-linux-gcc-3.4/ginac/../../ginac/parser/builtin_fcns.cpp|67| error: ISO C++ forbids casting between pointer-to-function and pointer-to-object make[2]: *** [builtin_fcns.lo] Error 1 The C++98 standard [expr.reinterpret.cast] does not allow reinterpret_cast(void*) reinterpret_cast(function_pointer) But the ability to do so is important for a lot of practical uses. So soon after the C++98 standard was approved, a language defect report was filed on this topic, see http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#195 The result is that compilers will be allowed to support reinterpret_cast conversions of function pointers to other (pointers) types, and vice a versa. Such conversions work with *current* compilers (GCC 4.x), but don't work with older ones, hence this patch. --- diff --git a/ginac/parser/default_reader.tpl b/ginac/parser/default_reader.tpl index ae36dde0..006fb908 100644 --- a/ginac/parser/default_reader.tpl +++ b/ginac/parser/default_reader.tpl @@ -59,7 +59,7 @@ static reader_func encode_serial_as_reader_func(unsigned serial) { uintptr_t u = (uintptr_t)serial; u = (u << 1) | (uintptr_t)1; - reader_func ptr = reinterpret_cast((void *)u); + reader_func ptr = (reader_func)((void *)u); return ptr; }