views:

66

answers:

2

What is the closest Core Foundation function to the functionality of NSLog?

+1  A: 

NSLog is built on top of the Apple System Log facility. Run man 3 asl to see the man page for this. You can use asl directly, but unless there's a reason, you can just keep using NSLog. Just include and link to Foundation if you want to avoid linking to Cocoa.

You can also just print to stderr if you want.

wbyoung
+2  A: 

CFShow() is similar, but without the prefix stuff. Or, as wbyoung says, use NSLog(). If you don’t want to use Objective-C, the following is perfectly valid (although it requires linking against Foundation.framework):

#if __cplusplus
extern "C" {
#endif
void NSLog(CFStringRef format, ...);
void NSLogv(CFStringRef format, va_list args);
#if __cplusplus
}
#endif

int main (int argc, const char * argv[])
{
    NSLog(CFSTR("Hello, World! %u"), 42);
    return 0;
}
Ahruman
CFShow seems to be what I'm looking for, and thanks for the other suggestion too.
invariant