]> www.ginac.de Git - ginac.git/commitdiff
Use C style cast when converting void* into function pointer.
authorAlexei Sheplyakov <alexei.sheplyakov@gmail.com>
Wed, 6 Jan 2010 17:55:43 +0000 (19:55 +0200)
committerJens Vollinga <jensv@nikhef.nl>
Thu, 14 Jan 2010 12:24:16 +0000 (13:24 +0100)
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

index ae36dde07fd61bb75cddd34e8aa036847ad61f42..006fb908c28402f2d61fa5cacdee904788a091b7 100644 (file)
@@ -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;
 }