#2213 glob.h does not compile as C++

OTHER
unread
nobody
None
Bug
none
Unknown
False
2014-04-25
2014-04-25
Daniele
No

It seems MinGW's implementation of glob.h doesn't compile under C++. I don't know if it's supposed to, but it would be really nice if it did.

Currently, glob.h declares glob() as follows (line 144):

GLOB_INLINE int glob
( const char *__pattern, int __flags, int (*__errfunc)(), glob_t *__data )
{ return __mingw_glob( __pattern, __flags, __errfunc, __data ); }

but __mingw_glob wants a int (*)( const char *, int ) as the __errfunc parameter.

Notice the __errfunc parameter has a empty parameter list, which has different meanings in C and C++: variable/unspecified arguments in C, or exactly zero arguments in C++. Also, C++ is a lot more strict in this respect, so it doesn't compile as C++.

The solution is very simple, declare glob() as follows:

GLOB_INLINE int glob
( const char *__pattern, int __flags, int (*__errfunc)( const char *, int ), glob_t *__data )
{ return __mingw_glob( __pattern, __flags, __errfunc, __data ); }

Using the proper function pointer type fixes the compilation for me.

Discussion