Don’t get the title wrong, I like GCC, but there are a few things that don’t trigger a warning in GCC, but do on Borland’s, which are quite useful and important.
The main thing I miss is the warning that Borland gives you when a variable is given a value that is never used. As I wrote more than a week ago GCC does not warn you about unused variables if they are assigned a value after they are declared. Which in xine tends to happen quite some times.
This is pretty important because, even if GCC is good enough not to emit the variable if it’s not used, if the assigned value is the return value of a function, the function call is unlikely to be optimised away. Pure and constant functions should be optimised away, but for functions the compiler has no clue about (which is the common status for non-static functions unless you tell it otherwise) the call is still executed, as it might change the global state variables. If the call is expensive, it would be a waste of CPU.
So I first tried ICC, remembering it used to have nicer and stricter warnings than GCC. Unfortunately even after installing it, getting a license key and opening a new shell with the environment set up, I get this:
/usr/include/stdlib.h(140): error: identifier "size_t" is undefined
extern size_t __ctype_get_mb_cur_max (void) __THROW __wur;
As you can guess, it’s not very nice that size_t
results undefined, and indeed it can’t even complete the ./configure
run.
Then I decided to try Sun’s compiler. I remembered Donnie having an ebuild for sunstudio
on his overlay, so I downloaded that and installed sunstudio. I had to fix a bit the build system of xine because Sun’s compiler was detected only under Solaris for PThread support, while of course you can use Sun’s compiler under Linux too.
After completing the ./configure
run properly, I’ve started seeing issues with xine’s code.. well I expected that. Mostly, the short form of the ternary operation (foo ? : bar
, which is equivalent to foo ? foo : bar
but with a single evaluation of foo) is not supported - I suppose it’s a GNU extension - but that’s not difficult to fix by avoiding that form…
The problems started the moment it compiled the first source file for xine-lib
itself (rather than its tools):
c99: Warning: illegal option -fvisibility=hidden
"../../../src/xine-engine/xine.c", line 83: internal compiler error: Wasted space
c99: acomp failed for ../../../src/xine-engine/xine.c
Now with all the good will I have, what should “Wasted space” mean to me‽
The illegal option is also a nice thing to see, considering that I test that during the ./configure
phase, and Sun’s compiler answers me a lot like it works:
configure:49543: checking if compiler supports -fvisibility=hidden
configure:49560: sunc99 -c -features=extensions -errwarn=%all -fvisibility=hidden conftest.c >&5
c99: Warning: illegal option -fvisibility=hidden
configure:49567: $? = 0
configure:49584: result: yes
Sincerely, I start to think a lot lately when I read about Sun wanting the good of Free Software. I had a few people telling me that xine lacks support for Solaris, Sun Studio compiler, UltraSPARC architecture, … well it’s not like it’s easy to support those, considering that Solaris for x86 is quite slow, and wasn’t working under VirtualBox for a while - it should work now but I haven’t had time to look at it yet, SunStudio for Linux fails, as I just noted, and the only way to get a decent Sun system for a standalone developer is looking and hoping at second hand offers on eBay and similar (a T2 basic server costs about $15K, a bit out of my league, for optimising xine, and as far as I can see all their workstation are now AMD64-based — or x64 as they call it, but I hate that market name as it really means nothing).
Maybe they are just interested in enterprise Free Software, but still… I sincerely think they have the right cards to make some difference, but I can’t see much Free Software development, beside the usual enterprise one, going on with Sun systems in the next future. Which is a bit sad considering I’ve seen my Ultra5 outpowering an Athlon almost twice its frequency…
I guess your installation of ICC is broken because normally size_t is defined. Another explanation would be that the configure script calls the compiler with options that are not compatible with icc.
I’ve just used emerge icc to install it, so if it’s broken, the ebuild is broken most likely. I doubt it’s any option because it fails during the first compiler’s sanity check, but I’ll doublecheck tomorrow for safety.
Do you know about pure functions in GCC?http://gcc.gnu.org/onlinedo…Theoretically marking such functions as pure manually should allow the compiler to be able to optimize them away if unused. Not sure if it actually does, but…To quote the GCC manual:Many functions have no effects except the return value and their return value depends only on the parameters and/or global variables. Such a function can be subject to common subexpression elimination and loop optimization just as an arithmetic operator would be. These functions should be declared with the attribute pure. For example, int square (int) __attribute__ ((pure));says that the hypothetical function square is safe to call fewer times than the program says.Some of common examples of pure functions are strlen or memcmp. Interesting non-pure functions are functions with infinite loops or those depending on volatile memory or other system resource, that may change between two consecutive calls (such as feof in a multithreading environment).The attribute pure is not implemented in GCC versions earlier than 2.96.
I know that Mart, and I did note that 😉
[Emphasis added]Unfortunately most of custom functions for programs are not marked as pure or constant even though they are for the simple reason that not everybody likes messing with compilers’ attributes. Thus the problem is still there.
Mart Raudsepp wrote:”Many functions have no effects except the return value and their return value depends only on the parameters and/or global variables.””Some of common examples of pure functions are strlen”This is contradicting. strlen is not pure according to that definition. It takes the parameter const char *s. But the return value does not only depend on the value of s and global variables. It also depends on the content of the memory location pointed to by s (and the following locations until the terminator). The content of those memory locations can of course change between calls to strlen with the same value of s. If s is allowed to point to something else than a global variable including a terminator (which it is), then it is proven that strlen is not pure.
@strlen()@ is indeed not a pure function, it’s a constant function though. The compiler can still optimise it, but not as much as a pure function.Indeed, the fact that @strlen()@ is non-pure (but constant) is what makes it important to not call it multiple time with the same (non-static) parameter.