[swift-evolution] [Pitch] Remove transparent bridging between Swift strings and char *
Dmitri Gribenko
gribozavr at gmail.com
Wed Jun 22 13:36:02 CDT 2016
On Wed, Jun 22, 2016 at 9:37 AM, Kenny Leung via swift-evolution
<swift-evolution at swift.org> wrote:
> Hi All.
>
> In the spirit of Chris’ focus on Swift 3 message…
>
> I’ve been working on calling C code that takes “const char * const *” arguments, and it ain’t easy, but that can be left for a future proposal…
>
> What does surprise me is that Swift String bridges directly into “char *” arguments in C as nul-terminated C strings, apparently preserving unicode and all. I can find nothing on bridging to “char *” in “Using Swift with Cocoa and Objective-C"
I think it is too useful for the C interop that it would not be
feasible for it to be removed completely. One tweak that I think we
should consider making is removing this implicit conversion when
calling Swift code, and only leave it for calling imported functions.
The reasoning is that Swift code should not be using
UnsafePointer<UInt8> to pass strings around.
We might need to leave an escape hatch (an underscored attribute) to
opt into this behavior for the overlays though.
Dmitri
--
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com>*/
More information about the swift-evolution
mailing list