[swift-dev] quick, spot the UB in this code:

Dmitri Gribenko gribozavr at gmail.com
Wed Apr 6 23:58:36 CDT 2016


On Wed, Apr 6, 2016 at 9:54 PM, Daniel Dunbar <daniel_dunbar at apple.com> wrote:
> Could we get a method that takes a [UInt8] directly and performs the same basic function?

I think the root of the surprise here is that the compiler converts
[UInt8] into an unsafe pointer.  This is appropriate when the callee
is a C API, but usually not appropriate when it is a Swift API.  This
is not the first time when this implicit conversion causes surprise.
I think we should discuss scoping that conversion to only C and
Objective-C callees.

But I agree with you, we should have a similar operation that works on
arbitrary collections.

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-dev mailing list