Ville Syrjälä wrote:
On Fri, Aug 29, 2008 at 07:43:48PM +0100, Phil Endecott wrote:
Hi,
The prototype for DirectFBInit is:
DFBResult DirectFBInit(int *argc, char *(*argv[]));
It modifies argc/argv to remove the --dfb: arguments.
However, I believe that although the argument list is modified, the
actual arguments are not. Let me be more explicit: there is a pointer
argv, which points to an array of pointers X, which points to a series
of arrays of characters Y. X is changed but Y is not. If that's
correct then the prototype should indicate that the chars are const:
DFBResult DirectFBInit(int *argc, const char *(*argv[]));
Writing const there only says that the chars are const, not that the
array of pointers to them is const. I think.
Have I got that right?
In theory. However at least gcc doesn't like that. You can apparently
add two levels of constness before it it starts to yell. That is you
can make it 'char * * const argv[const]' but any deeper constness and
gcc wil complain. And of course that level of constness would mean we
can't reorganise the array contents.
I can only start to understand this sort of thing with some typedefs:
typedef const char const_char;
typedef const_char *const_char_ptr;
typedef const_char_ptr const_char_ptr_array[];
typedef const_char_ptr_array *const_char_ptr_array_ptr;
void foo(const_char_ptr_array_ptr x)
{
char c = (*x)[0][0];
}
gcc (4.1 & 4.3) seems happy with that.
Now that I look at the prototype it actually looks more fundementally
wrong.
'char *(*argv[])' == 'char **argv[]' which is to say an
array of pointers to pointers to char.
AFAIK it should be 'char *(*argv)[]' ie. a pointer to an array of
pointers to char. gcc 4.1 doesn't like this form however.
I've tried some trivial code and it seems happy; can you post an
example that fails?
Phil.
_______________________________________________
directfb-dev mailing list
directfb-dev@directfb.org
http://mail.directfb.org/cgi-bin/mailman/listinfo/directfb-dev