[Bioc-devel] evaluation of C post-increments changed in GCC 4.8.2

Robert Castelo robert.castelo at upf.edu
Thu Jun 12 14:45:28 CEST 2014


hi,

this is just a warning to developers who may have C code in their packages.

today i fixed a problem in the C code of the package VariantFiltering 
which can be reproduced with the following toy example.

=======test.c========
#include <stdio.h>
#include <ctype.h>

int main(void) {
   char msg[] = "Hello World!";
   char* p=msg;

   printf("%s\n", msg);
   while ((*p++=tolower(*p)));
     printf("%s\n", msg);

   return 0;
}
====================

after compiling this program stored as 'test.c' with the GCC compiler:

$ gcc -o test ./test.c

its execution shows the following output,

$ ./test
Hello World!
hello world!

when GCC has version 4.6.3 or lower. However, if you try to compile it 
with GCC version 4.8.2 (haven't tried any version > 4.6.3 and < 4.8.2) 
you get the following different output:

Hello World!
ello world!

my interpretation of this change, and probably the C gurus in the list 
can clear up this point, is that the evaluation of post-increments 
(i.e., x++, i++, p++, etc.) in C has changed the way it was done in GCC 
4.8.2 (and maybe even in earlier versions although not earlier than 4.6.3).

if i change the line that contains the post-increment 'p++' to the 
following one:

   while ((*p=tolower(*p))) p++;

then it works again as i expected with GCC 4.8.2.

so, if you have C code in your package you might want to inspect all 
your post-increments. actually, if you compile the C code with 
-Wunsequenced the gcc compiler will warn you about this potential problem.

see for instance (before the fix i sent gets through the build) the 
CHECK report of VariantFiltering for Mac OS X Snow Leopard and Mavericks 
which seem to use these two different flavors of GCC. While with Snow 
Leopard there is no apparent problem, in Maverics the installed version 
of GCC reports the following warnings:

Found the following significant warnings:
   methods-WeightMatrix.c:256:19: warning: unsequenced modification and 
access to 'q' [-Wunsequenced]
   methods-WeightMatrix.c:638:17: warning: unsequenced modification and 
access to 'q' [-Wunsequenced]

those lines contain the kind of use of post-increment i showed above and 
are the ones i had to fix.


greetings everyone,

robert.



More information about the Bioc-devel mailing list