[petsc-dev] Problem with PETSC_NULL and variadic functions
Matthew Knepley
knepley at gmail.com
Wed Nov 9 15:22:57 CST 2011
On Wed, Nov 9, 2011 at 9:19 PM, Jed Brown <jedbrown at mcs.anl.gov> wrote:
> On Wed, Nov 9, 2011 at 15:15, Satish Balay <balay at mcs.anl.gov> wrote:
>
>> <petscsys.h>
>> extern void* PETSC_NULL
>> <init.c>
>> static void* PETSC_NULL=0L [or null or nullptr - based on configure
>> determined flags]
>>
>
> You must not really mean "static".
>
>
>>
>> [so as to avoid language/functionality based #def() code in petscsys.h
>> - that could potentially cause issues like what we had with isinf()
>> stuff]
>>
>
> The problem is that C++ does not allow implicit conversion from void* to a
> different pointer type. Note how PetscMalloc needs an explicit cast. It is
> not possible to write
>
> int *x = malloc(sizeof(int));
>
> in C++, you need
>
> int *x = (int*)malloc(sizeof(int));
>
> If we unconditionally define PETSC_NULL to be (void*)0, then we cannot
> avoid requiring the user to make that cast all over the place.
>
So the problem is that in C++, when using a variadic function, you cannot
type PETSC_NULL directly into the argument list? When would you ever
do this? If an argument to Printf() is equal to PETSC_NULL, no problem. Its
only when PETSC_NULL is passed directly. Why not prevent that in
all PETSc variadic functions, which I think are only the prints.
Matt
--
What most experimenters take for granted before they begin their
experiments is infinitely more interesting than any results to which their
experiments lead.
-- Norbert Wiener
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-dev/attachments/20111109/9a0d69f6/attachment.html>
More information about the petsc-dev
mailing list