Everything you describe sounds to be in line with the intent of the language linkage feature.
Class members are specifically excluded from "C"
language linkage. According to examples in the Standard (C++11 §7.5/4), function pointer types within class member declarations, extern
declarations in any context, and all other function declarations do inherit the enclosing extern "C" {}
block. You're defining a language linkage besides "C"
but it would be least surprising to follow its example, perhaps with extra mapping between this
and self
.
The requirements are open, according to §7.5/2:
Use of a string-literal other than "C" or "C++" is conditionally-supported, with implementation-defined semantics. [ Note: Therefore, a linkage-specification with a string- literal that is unknown to the implementation requires a diagnostic. — end note ] [ Note: It is recommended that the spelling of the string-literal be taken from the document defining that language. For example, Ada (not ADA) and Fortran or FORTRAN, depending on the vintage. — end note ]
You could switch to a completely different language within the braces an it would be alright. (Although, grammatically, I suppose everything should parse as a C++ declaration or declaration-seq.)
According to that, though, you should use extern "Objective-C"
with a hyphen since the definitive document's title is "The Objective-C Programming Language."
EDIT: To be sure, calling through objc_msgSend
doesn't affect anything that the Standard specifies. Nowhere does it say how C++ functions are called. The added intermediate function is just machine-level instructions, beyond language semantics, and no different from the special instructions used to call into Pascal, Fortran, etc., e.g. by altering the order of parameters on the stack. I don't mean to compare your scheme to "switching to a completely different language within the braces," just to emphasize that there's plenty of headroom.
Taking the extern "C"
specification in the Standard as an example, it breaks a lot of things by fundamentally changing the ODR rule because C isn't required to support any mangling. So your scheme is allowed to break at least that much.