[swift-evolution] Making pointer nullability explicit (using Optional)

Dmitri Gribenko gribozavr at gmail.com
Tue Mar 22 12:23:55 CDT 2016


On Mon, Mar 21, 2016 at 4:14 PM, Jordan Rose via swift-evolution
<swift-evolution at swift.org> wrote:
> I've recorded everyone's feedback so far (mostly on the UnsafeBufferPointer
> issue) and opened a pull request:
> https://github.com/apple/swift-evolution/pull/219.

Thanks, Jordan!  I have a concern about the following point:

+- `Process.unsafeArgv` is a pointer to a null-terminated C array of C strings,
+ so its type changes from `UnsafeMutablePointer<UnsafeMutablePointer<Int8>>` to
+ `UnsafeMutablePointer<UnsafeMutablePointer<Int8>?>`, i.e. the inner pointer
+ type becomes optional. It is then an error to access `Process.unsafeArgv`
+ before entering `main`. (Previously you would get a null pointer value.)

I don't think that this error is defensible -- if you are writing some
library code, you just can't know whether you are being executed
before `main` or not.  This is a precondition that reusable code just
can't guarantee.

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