[petsc-users] Wrapping PetscFPrintf

Jed Brown jedbrown at mcs.anl.gov
Sat Nov 10 18:25:42 CST 2012


If you are getting garbage, run in valgrind and/or a debugger. Also make
sure the int sizes are converted correctly as for a direct call to printf.


On Sat, Nov 10, 2012 at 3:38 PM, Dominik Szczerba <dominik at itis.ethz.ch>wrote:

> Hi,
>
> I need to have a wrapper to PetscFPrintf and PetscSynchronizedFPrintf.
> I am aware of the problems and tried following as described here:
>
> http://c-faq.com/varargs/handoff.html
>
> So I have:
>
>         virtual bool VPrint(const char* format, va_list argp) = 0;
>         virtual bool Print(const char* format, ...) = 0;
>
> implemented as:
>
>         bool CXCoreReporting::VPrint(const char* format, va_list argp)
>         {
>                 vfprintf(stderr, format, argp);
>                 return true;
>         }
>
>         bool CXCoreReporting::Print(const char* format, ...)
>         {
>                 va_list argp;
>                 va_start(argp, format);
>                 VPrint(format, argp);
>                 va_end(argp);
>                 return true;
>         }
>
>
> Now the problem is that it just does not work... I still get trash
> when calling e.g. Print("%d", i).
> Does anyone see a way out?
>
> Many thanks
> Dominik
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20121110/c99a08e1/attachment.html>


More information about the petsc-users mailing list