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.

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 wonder
if gcc is simply buggy or is my C-fu too weak to understand such
constructs... Maybe we should just make it 'char ***argv'.

Not that argv needs to be a pointer to begin with since we never
change it, but changing that would break all existing users for
a cosmetic gain.

-- 
Ville Syrjälä
[EMAIL PROTECTED]
http://www.sci.fi/~syrjala/
_______________________________________________
directfb-dev mailing list
directfb-dev@directfb.org
http://mail.directfb.org/cgi-bin/mailman/listinfo/directfb-dev

Reply via email to