4

The method signature is...

- (void)blahBlahBlah:(NSString*)format, ... NS_FORMAT_FUNCTION(1,2) {

   va_list args; va_start(args,format);

   void(^SOME_BLOCK)(void) = ^{ [Heathens prayToJesusWith:
                           [NSString.alloc initWithFormat:kFMT       
                                                arguments:args];  }; ...
   va_end(args);
}

However Xcode whines about args inside the SOME_BLOCK... Cannot refer to declaration with an array type inside block. Why not? It's "in scope", no? Tried __block va_list to no avail. Advice? Rationales?

Alex Gray
  • 16,007
  • 9
  • 96
  • 118

1 Answers1

6

va_list is an opaque type that is implementation-dependent and platform-dependent. It could be that on your particular system is is implemented as some kind of array. Blocks cannot capture variables of array type. The C standard imposes certain restrictions on the use of va_list, but there is no explicit mention of any issues with blocks.

If you are sure that the block will run within the lifetime of this function (which it must otherwise anyway; because args is only meaningful between va_start and va_end), then one solution is to create another variable that is va_list *, set to &args, and then capture that and dereference it when you need to use it.

newacct
  • 119,665
  • 29
  • 163
  • 224