From simon.urbanek at r-project.org  Thu Apr 19 20:17:56 2007
From: simon.urbanek at r-project.org (Simon Urbanek)
Date: Thu, 19 Apr 2007 14:17:56 -0400
Subject: [Rd] printf capture
In-Reply-To: <46277D42.9080203@altk.com>
References: <461E02EE.7040105@altk.com>
	<Pine.LNX.4.64.0704121122480.26905@gannet.stats.ox.ac.uk>
	<461E3F8F.4050801@altk.com>
	<Pine.LNX.4.64.0704121558260.11792@gannet.stats.ox.ac.uk>
	<46277D42.9080203@altk.com>
Message-ID: <097DF923-E961-4707-B29C-81F3C85B9461@r-project.org>


On Apr 19, 2007, at 10:31 AM, mel wrote:

> Prof Brian Ripley a ?crit :
>
>> You can always link in a wrapper that defined printf and passes  
>> the arguments to Rprintf.
>
> I apologize but confess i didn't completely understand this  
> suggestion.
>

The wrapper:

#include <R.h>

int printf(const char *format, ...) {
   va_list (ap);
   va_start(ap, format);
   Rvprintf((char*)format, ap);
   va_end(ap);
   return 0;
}

If you link this in your project (simply create a separate object  
file with this), the project will be using Rprintf via this wrapper  
instead of printf from libc. Note that you shouldn't be relying on  
the return value literally, otherwise you're in trouble ;).

Cheers,
Simon

>> It's documented in 'Writing R Extensions'.
>>   The defines used for compatibility with @Sl{} sometimes causes
>>   conflicts (notably with Windows headers), and the known
>>   problematic defines can be removed by defining @code 
>> {STRICT_R_HEADERS}.
>
> Yes, i added
> #define STRICT_R_HEADERS
> in my cpp code, and the redefinition warning vanishes indeed.
>
> Many thanks for your precise tips and my apologies for the late  
> answer.
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
>



[Rd] printf capture
Simon Urbanek