[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Newbie: how to handle different prototypes?
From: |
gnoop |
Subject: |
Re: Newbie: how to handle different prototypes? |
Date: |
Thu, 23 Jun 2005 00:39:53 -0700 |
On Wednesday, June 22, 2005, at 11:10PM, Ralf Wildenhues <address@hidden> wrote:
>Hi,
>
>* address@hidden wrote on Wed, Jun 22, 2005 at 10:17:02PM CEST:
>> I have a basic question that I couldn't find in the info docs or the
>> goat book. What's the right way to deal with a prototype for a system
>> library function that differs between platforms? I know how to check
>> for headers and libraries, but don't know what the autotools way is to
>> get around different prototypes.
>>
>> For example, on linux the scandir prototype is:
>>
>> int scandir(const char *dir, struct dirent ***namelist,
>> int(*select)(const struct dirent *),
>> int(*compar)(const struct dirent **, const struct dirent **));
>>
>> and on darwin it's:
>>
>> int
>> scandir(const char *dirname, struct dirent ***namelist,
>> int (*select)(struct dirent *),
>> int (*compar)(const void *, const void *));
>>
>> I.e. the const is missing from darwin's 3rd parameter.
>
>Can't you just ignore this difference in your program? If you pass a
>select function which eats a const argument, you are within ANSI C
>bounds in either case. Ignore the warning some compiler may emit --
>it should rather be fixed.
At least some C++ compilers fail. g++ fails with an err. gcc just issues a
warning.
>
>If you ever encounter significant function definition differences, you
>may look at the chapter
> info Autoconf 'Library Functions'
>of the manual and the corresponding implementations in
>autoconf/function.m4 to search for a macro similar to your needs which
>you can adjust. Be sure to use published macros only within your macro.
>
Thanks, Ralf. I finally found after following your reference that the info
section that has examples for my problem is the 'Types' node (duh!). And
there and looking at actypes.m4 I found that AC_TYPE_SIGNAL is a nice
simple example of checking for and defining a data type.
In the meantime, a solution I came up with was to define a macro using
the AC_PROTOTYPE macro in the autoconf macro archive, which defines
SCANDIR_ARG3 with the appropriate type. (Note, C++ is required to raise
the compilation error.)
AC_DEFUN([AC_PROTOTYPE_SCANDIR],[
AC_LANG_PUSH(C++)
AC_PROTOTYPE(scandir,
[
#include <dirent.h>
],
[
const char * dir = 0;
struct dirent ***namelist = 0;
int(*select)(ARG3) = 0;
scandir(dir, namelist, select, alphasort);
],
ARG3, [const struct dirent *, struct dirent *])
AC_LANG_POP(C++)
])