{"id":698,"date":"2012-11-06T15:41:43","date_gmt":"2012-11-06T14:41:43","guid":{"rendered":"http:\/\/trigonakis.com\/blog\/?p=698"},"modified":"2013-04-24T13:48:06","modified_gmt":"2013-04-24T12:48:06","slug":"gcc-64bits-addressing-function-returns-32bits-pointer","status":"publish","type":"post","link":"http:\/\/trigonakis.com\/blog\/2012\/11\/06\/gcc-64bits-addressing-function-returns-32bits-pointer\/","title":{"rendered":"GCC &#8212; 64bits addressing: function returns 32bits pointer"},"content":{"rendered":"<p>Today, it was the second time I stepped on an interesting problem with GCC \u00a0(well, it is actually a behavior). I created a function which returns a <code>void*<\/code> in a .c file. This C file was then compiled and added in a library (.a). When I used this function in an application, I was getting a <code>void*<\/code> pointer were the 32 most significant bits were either zeroed (<code>0x00000000...<\/code>) or set to 1 (<code>0xFFFFFFFF...<\/code>). My application is 64bit!!<\/p>\n<p>For example, the debug prints I added would return:<\/p>\n<pre lang=\"bash\">[lib] allocated 0x7f756d6fa048\r\n[app] allocated 0x6d6fa048<\/pre>\n<p>where you can see the &#8220;conversion&#8221;.<\/p>\n<p><strong>What was the problem?<\/strong> After some time of debugging, I realized that I had forgotten to include the aforementioned function in the corresponding header file :|. So, although GCC could find the function in the library I was linking the application to, I guess it was assuming a wrong return value\/header for that function.<\/p>\n<p><strong>The conclusion:<\/strong> Be more careful \ud83d\ude09<\/p>\n<p>PS. I am using the following version of GCC:<\/p>\n<pre lang=\"bash\">$ gcc -v\r\nUsing built-in specs.\r\nCOLLECT_GCC=gcc\r\nCOLLECT_LTO_WRAPPER=\/usr\/lib\/gcc\/x86_64-linux-gnu\/4.6\/lto-wrapper\r\nTarget: x86_64-linux-gnu\r\nConfigured with: ..\/src\/configure -v --with-pkgversion='Ubuntu\/Linaro 4.6.3-1ubuntu5' \r\n--with-bugurl=file:\/\/\/usr\/share\/doc\/gcc-4.6\/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ \r\n--prefix=\/usr --program-suffix=-4.6 --enable-shared --enable-linker-build-id --with-system-zlib \r\n--libexecdir=\/usr\/lib --without-included-gettext --enable-threads=posix \r\n--with-gxx-include-dir=\/usr\/include\/c++\/4.6 --libdir=\/usr\/lib --enable-nls --with-sysroot=\/ \r\n--enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes \r\n--enable-gnu-unique-object --enable-plugin --enable-objc-gc --disable-werror \r\n--with-arch-32=i686 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu \r\n--host=x86_64-linux-gnu --target=x86_64-linux-gnu\r\nThread model: posix\r\ngcc version 4.6.3 (Ubuntu\/Linaro 4.6.3-1ubuntu5)<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Today, it was the second time I stepped on an interesting problem with GCC \u00a0(well, it is actually a behavior). I created a function which returns a void* in a .c file. This C file was then compiled and added in a library (.a). When I used this function in an application, I was getting [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":699,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[1],"tags":[29,204,9,27],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"http:\/\/trigonakis.com\/blog\/wp-content\/uploads\/2012\/11\/gccegg-65.png","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p1ouW6-bg","_links":{"self":[{"href":"http:\/\/trigonakis.com\/blog\/wp-json\/wp\/v2\/posts\/698"}],"collection":[{"href":"http:\/\/trigonakis.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/trigonakis.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/trigonakis.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/trigonakis.com\/blog\/wp-json\/wp\/v2\/comments?post=698"}],"version-history":[{"count":12,"href":"http:\/\/trigonakis.com\/blog\/wp-json\/wp\/v2\/posts\/698\/revisions"}],"predecessor-version":[{"id":722,"href":"http:\/\/trigonakis.com\/blog\/wp-json\/wp\/v2\/posts\/698\/revisions\/722"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/trigonakis.com\/blog\/wp-json\/wp\/v2\/media\/699"}],"wp:attachment":[{"href":"http:\/\/trigonakis.com\/blog\/wp-json\/wp\/v2\/media?parent=698"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/trigonakis.com\/blog\/wp-json\/wp\/v2\/categories?post=698"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/trigonakis.com\/blog\/wp-json\/wp\/v2\/tags?post=698"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}