{"id":703,"date":"2022-08-30T15:05:46","date_gmt":"2022-08-30T15:05:46","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/09\/problem-about-gcc4-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:05:46","modified_gmt":"2022-08-30T15:05:46","slug":"problem-about-gcc4-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/problem-about-gcc4-collection-of-common-programming-errors\/","title":{"rendered":"problem about gcc4-Collection of common programming errors"},"content":{"rendered":"<ul>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/f9401202ab73e624cc82800b0fff1489?s=128&amp;d=identicon&amp;r=PG\" \/><br \/>\nKonrad Rudolph<br \/>\nc++ osx templates undefined-reference gcc4<br \/>\nPremiseI\u2019m using a C library (from C++) which provides the following interface:void register_callback(void* f, void* data); void invoke_callback();ProblemNow, I need to register a function template as a callback and this is causing me problems. Consider the following code:template void my_callback(void* data) { \u2026 }int main() {int ft = 42;register_callback(reinterpret_cast(&amp;my_callback), &amp;ft);invoke_callback(); }This gives me the following linker error (using g++ (GCC) 4.5.1 on OS X but works on most other combinations of compiler version \/ platform):Undefined symbols for architecture x86_64:&#8221;void my_callback(void*)&#8221;, referenced from:<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/285d6b2d5fb4a77f8527bb4ecbb560d6?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nbgp2000<br \/>\ncmake linker-error gcc4<br \/>\nI am developing a library and need to make sure it compiles with 4.1.2(I know, it brings me no pleasure). So on a Fedora 14 Machine I downloaded, compiled and installed GCC41.Now in CMake I only change the following to variables CMAKE_CXX_COMPILER=\/opt\/gcc41\/bin\/c++41 CMAKE_C_COMPILER=\/opt\/gcc41\/bin\/gcc41It compiles fine,<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/4123069aca76aa3b0a12da3e800e22d9?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nsquashed.bugaboo<br \/>\nc++ python linux boost gcc4<br \/>\nUgh! I have hit one of those errors where I am really clueless. I have built\/installed Python (2.7.1) and I&#8217;ve built\/installed boost (1.44.0) against that version of python. I don&#8217;t see any errors in my boost build, everything goes through fine. When I turn to d<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/982465269bdfd8f6e1790677fa3aed41?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nA Fog<br \/>\nc++ c overflow integer-overflow gcc4<br \/>\nPossible Duplicate:Best way to detect integer overflow in C\/C++ No, this is not a duplicate. The issue is the same but the question is different.The gcc compiler can optimize away an overflow check (with -O2), for example:int a, b; b = abs(a); \/\/ will overflow if a = 0x80000000 if (b &lt; 0) printf(&#8220;overflow&#8221;); \/\/ optimized awayThe gcc people argue that this is not a bug. Overflow is undefined behavior, according to the C standard, which allows the compiler to do anything. Apparently, anything includes assuming that overflow never happens. Unfortunately, this allows the compiler to optimize away the overflow check.The safe way to check for overflow is described in a recent CERT paper. This paper recommends doing something like this before adding two integers:if ( ((si1^si2) | (((si1^(~(si1^si2) &amp; INT_MIN)) + si2)^si2)) &gt;= 0) { \/* handle error condition *\/ } else {sum = si1 + si2; }Apparently, you have to do something like this before every +, -, *, \/ and other operations in a series of calculations when you want to be sure that the result is valid. For example if you want to make sure an arra<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/e7e5ad22ffdae368ff96f4e4b3e4119b?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nArne Bergene Fossaa<br \/>\ngcc gcc4<br \/>\nI am observing a difference when trying to do the same operation on GCC 4.4 and GCC 4.5. Because the code I am doing this with is proprietary, I am unable to provide it, but I am observing a similar failure with this simple test case.What I am basically trying to do is have one shared library (libb) depend on another shared library (liba). When loading libb, I assume that liba should be loaded as well &#8211; even though libb is not necessarily using the symbols in liba.What I am observing is when I compile with GCC 4.4, I observe that the lib<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/815ee86e14bbedd4f353cad0680c7be5?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nMat<br \/>\nc linker gentoo gcc4<br \/>\nI&#8217;m on gentoo linux with GCC 4.4.5 installed. I can compile and link such program without any errors using gcc main.c -o main, and the command .\/main returns result correctly. [main.c] #include #include int main(void) {double c = ceil(2.5);printf(&#8220;The cei<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/fd05beac92923ba9d75c447ff87476b0?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nKunal P.Bharati<br \/>\ngcc gcc4<br \/>\nI am using Brian Gladman&#8217;s library for EAX encryption in one of my project. The problem is the code works on my loc<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/fea078db346a2148b1367633bbf6a5ee?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nWade<br \/>\nc exception compiler-optimization gcc4<br \/>\nUsing gcc 4.7:$ gcc &#8211;version gcc (GCC) 4.7.0 20120505 (prerelease)Code listing (test.c):#include struct test {int before;char start[0];unsigned int v1;unsigned int<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/5bd1b4fb8070088e859a71678139da87?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nChung-Ju Wu<br \/>\nc c99 gcc4 sequence-points<br \/>\nThere is a code fragment that GCC produce the result I didn&#8217;t expect:(I am using gcc version 4.6.1 Ubuntu\/Linaro 4.6.1-9ubuntu3 for target i686-linux-gnu)[test.c]#include int *ptr;int f(void) {(*ptr)++;return 1; }int main() {int a = 1, b = 2;ptr = &amp;b;a = b++ + f() + f() ? b : a;printf (&#8220;b = %d\\n&#8221;, b);return a; }In my understanding, there is a sequence point at function call. T<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/0cb056c5eacbab294f295f17b759a271?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nYuji<br \/>\nlinker gfortran gcc4<br \/>\nI&#8217;m trying to compile a code (not mine) that consists of mixed Fortran and C source files, which are compiled into a library. This library can either be linked against directly, or (more usefully) driven from a python class. I have previously successfully built the code as 32-bit with g77 and gcc, but I&#8217;ve encountered a situation in which the code uses big chunks of memory, and needs to be 64-bit.I&#8217;ve attempted to build as both 64-bit only, or as a universal b<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/fd7e4866d0f73713689be7600a2ddcb0?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nuser1242145<br \/>\nheader-files undefined-reference gcc4 perfect-hash<br \/>\nI am using gcc 4.4.3 on ubuntu. I installed cmph library tools 0.9-1 using commandsudo apt-get install libcmph-toolsNow, when I tried to compile example program vector_adapter_ex1.c , gcc is able to d<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/88fcbc16af97a555e56078a2c6358963?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nVladimir Still<br \/>\ngcc arm gcc4<br \/>\nI&#8217;m trying to compile GCC on synology DS109 NAS disk which is powered by Marvell Kirkwood mv6281 ARM Processor. It is currently running quite outdated GCC 4.2.3 which is the newest vesion that I found for it in binaries.I tried GCC 4.7.1 and 4.6.3 both with same result during make phase:build\/genflags.o build\/rtl.o build\/read-rtl.o build\/ggc-none.o build\/vec.o build\/min-insn-modes.o build\/gensupport.o build\/print-rtl.o build\/read-md.o build\/errors.o ..\/build-armv5tel-unknown-linux-gnueabi\/libiberty\/libiberty.a build\/rtl.o: In function `rtvec_alloc&#8217;: \/volume1\/public\/gcc-4.6.3\/build\/gcc\/..\/..\/gcc-4.6.3\/gcc\/rtl.c:153: undefined re<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/361f374b0f2f2a778222e88a2bb8d87f?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nClaire Huang<br \/>\nc++ compiler ubuntu g++ gcc4<br \/>\nI tried to install gcc 4.5 on ubuntu 10.04 but failed. Here is a compile error that I don&#8217;t know how to solve. Is there anyone successfully install the latest gcc on ubuntu? Following is my steps and the error message, I&#8217;d like to know where is the problem&#8230;.Step1: download these files:gcc-core-4.5.0.tar.gz gcc-g++-4.5.0.tar.gz gmp-4.3.2.tar.bz2 mpc-0.8.1.tar.gz mpfr-2.4.2.tar.gzStep2: Unzip above filesStep3: move gmp, mpc, mpfr to the gcc-4.5.0\/ directory.mv gmp-4.3.2 gcc-4.5.0\/gmp mv mpc-0.8.1 gcc-4.5.0\/mpc mv mpf<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.stack.imgur.com\/fEHsz.jpg?s=32&amp;g=1\" \/><br \/>\nShredderroy<br \/>\nc hashtable glib gcc4<br \/>\nI have the following simple lines of code:#include #include void my_func () {GHashTable htbls[3]; \/* ASSU<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/6c62974c42aaa2932d33117802a8284c?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nboundless08<br \/>\ndebian gcc4 hiphop<br \/>\nI&#8217;m having trouble installing gcc 4.6.3 on Debian squeeze. 4.4 is currently installed but I need 4.6.x to run php-hiphop. I&#8217;ve tried looking for similar problems but haven&#8217;t found any with the error I have.I install using these instructions:wget ftp:\/\/ftp.gnu.org\/gnu\/gcc\/gcc-4.6.3\/gcc-4.6.3.tar.gz tar -xzvf gcc-4.6.3.tar.gz cd gcc-4.6.3 .\/contrib\/download_prerequisites cd .. mkdir objdir cd objdir \u00a3PWD\/..\/gcc-4.6.3\/configure &#8211;prefix=\/opt\/gcc-4.6.3 make make installon the make command everything seems to be going fine for a good 20 or more minutes then, BLAMO! This pops up:make[5]: Entering directory `\/root\/objdir\/x86_64-unknown-linux-gnu\/32\/libgcc&#8217; # If this is the top-level multilib, build all the other # multilibs. \/root\/objdir\/.\/gcc\/xgcc -B\/root\/objdir\/.\/gcc\/ -B\/opt\/gcc-4.6.3\/x86_64-unknown-linux-gnu\/bin\/ -B\/opt\/gcc-4.6.3\/x86_64-unknown-linux-gnu\/lib\/ -isystem \/opt\/gcc-4.6.3\/x86_64-unknown-linux-gnu\/include -isystem \/opt\/gcc-4.6.3\/x86_64-unknown-linux-gnu\/sys-include -g -O2 -m32 -O2 -g -O2 -DIN_GCC -W -Wall -Wwrite-strings -Wcast-qual -Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition -isystem .\/include<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/fba04445368e87e00dcd50a8c845e4de?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\ndjin<br \/>\nosx gcc linker gcc4<br \/>\nI am trying to install gcc-4.0.1 on a mac with Darwin 12.1.0 . I did the configuration with .\/configure &#8211;prefix=\/usr\/local\/gcc-4.0.1 &#8211;enable-languages=c,c++ . It give<\/li>\n<\/ul>\n<p id=\"rop\"><small>Originally posted 2013-11-09 21:42:05. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>Konrad Rudolph c++ osx templates undefined-reference gcc4 PremiseI\u2019m using a C library (from C++) which provides the following interface:void register_callback(void* f, void* data); void invoke_callback();ProblemNow, I need to register a function template as a callback and this is causing me problems. Consider the following code:template void my_callback(void* data) { \u2026 }int main() {int ft = [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-703","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/703","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=703"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/703\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=703"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=703"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=703"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}