iphone - Using va_list and getting EXC_BAD_ACCESS -


similar how nslog takes variable argument list, want create own method.

i have method declared when try access 'args' variable, exec_bad_access. i'm not doing correctly here?

- (void)info:(nsstring *)formatstring, ... {        va_list args;     va_start(args, formatstring);      nslog(@"formatstring value: %@", formatstring);      // following line causes exec_bad_access     nslog(@"args value: %@", args);      // i'm trying do:     nslog(formatstring, args);      va_end(args);                } 

i following 'va_list in cocoa' section blog: http://cocoawithlove.com/2009/05/variable-argument-lists-in-cocoa.html

there couple of mistakes in code. firstly, args cannot printed directly is. reference several arguments, , trying print using nslog("%@") not work. can use nslogv() print (e.g. nslogv(format, args);) instead.

or can do, , use function:

void print (nsstring *format, ...) {     va_list args;     va_start(args, format);      fputs([[[[nsstring alloc] initwithformat:format arguments:args] autorelease] utf8string], stdout);      va_end(args); } 

Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -