char * const argv
For the past few days I've been poking around dasher, cairo, pango still. Suggested to them and now the dasher project finally has a URL that can be memorized: http://www.dasher.org.uk/
. Cleaned up a few uninitialized memory problems and a few leaks in dasher, all reported by valgrind. Also helped Owen pin down a problem
in cairo with font caching. Then turned to porting and updating the cairo-demo module to the latest cairo api. From Carl Worth's Makefile's I discovered a few good gcc warning options to add besides -Wall to catch more possible problems in the code. Now I get a ton of warnings compiling anything. Was trying to fix them in FriBidi
where I got stuck:
One of the warnings I've requested for is the -Wwrite-strings, that warns when you assign an string literal to a
instead of a
const char *
. Everything's fine with that, except for the getopt_long call:
int getopt_long_only(int argc, char * const argv,
const char *optstring,
const struct option *longopts, int *longindex);
The manual has a note at the end:
POSIX.2, provided the environment variable POSIXLY_CORRECT is set.
Otherwise, the elements of argv aren’t really const, because we permute
them. We pretend they’re const in the prototype to be compatible with
So my questions are:
- getopt_long is not a POSIX function. Why should they lie in its prototype too?
- Why the hell is it
char * const argv and not
const char * const argv? Ok, I know why, because they do string surgery to return the option out form something like --foo=bar.
And I get this all because I'm overriding argv to fix my applications name before passing to getopt, and that thing happens to be an string literal, sigh...
One of the other new warnings that I like is the -Wfloat-equal. That one warns whenever you a floating-point number in an equality condition. That's briliant! If you have every programmed a computer graphics or (worse:) computational geometry algorithm, you know that no two floats ever match with equality...
For the curious in you, here is my complete gcc options:
-mcpu=pentium4 -march=pentium4 -g -O3 -Wall -Wextra -Wfloat-equal -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wredundant-decls -Wold-style-definition -Wmissing-noreturn -Wdeclaration-after-statement -Wshadow -Wendif-labels -Wlarger-than-4000 -Wpointer-arith -Wbad-function-cast -Wcast-qual -Wcast-align -Wwrite-strings -Winline"
[Ah, I really got to finish the cairo-demo thing and get to the Summer of Code project. It's getting too late...]