[PATCH] 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<function_pointer>(void*) reinterpret_cast<void*>(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. --- ginac/parser/default_reader.tpl | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/ginac/parser/default_reader.tpl b/ginac/parser/default_reader.tpl index ae36dde..006fb90 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<reader_func>((void *)u); + reader_func ptr = (reader_func)((void *)u); return ptr; } -- 1.6.5
participants (1)
-
Alexei Sheplyakov