mverderese
mverderese

Reputation: 5334

What exactly does "Enable Strict Checking of objc_msgSend Calls" mean?

This is what I'm referring to:
enter image description here

From what I've read, an objc_msgSend is essentially what is happening at the c level when you send an Objective-C message, and this setting set to Yes ensures that the message being sent has the same number of arguments as the the receiver is expecting.

Is this correct? Also what are the advantages and disadvantages to setting this to Yes or No? Should I only set this to Yes in development and No in production?

Upvotes: 9

Views: 3800

Answers (2)

nielsbot
nielsbot

Reputation: 16032

There's a presentation "What's new in LLVM" on Apple's website (text of the presentation is here).

It looks like the compiler will now (optionally) strictly check the types of calls to obj_msgSend. You will have use a correctly-typed function pointer in place of directly calling objc_msgSend.

Example given:

#include <objc/message.h>
void foo(void *object) {
  typedef void (*send_type)(void *, SEL, int);
  send_type func = (send_type)objc_msgSend;
  func(object, sel_getUid("foo:"), 5);
}

Upvotes: 7

Joshua D. Boyd
Joshua D. Boyd

Reputation: 4856

You are essentially correct, yes.

Apple sets it to Yes by default because it helps to find errors faster. The only reason to set it to No would be because you are compiling legacy code that hasn't been updated to compile cleanly with this option on.

"Enable Strict Checking of objc_msgSend Calls" is a compile time check, not run time, so there is no benefit to turning it off in production.

Upvotes: 7

Related Questions