[swift-users] C Pointers and Memory

James Campbell james at supmenow.com
Fri Jul 29 02:55:40 CDT 2016


So this:

if let data = someArrayGeneratingFunction() {
  cFunction(UnsafeMutablePointer(data))
}

Has issues with the array passed to c getting corrupted, but this doesn't:

let data = someArrayGeneratingFunction()

if let data = data {
  cFunction(UnsafeMutablePointer(data))
}

*___________________________________*

*James⎥Head of Trolls*

*james at supmenow.com <james at supmenow.com>⎥supmenow.com <http://supmenow.com>*

*Sup*

*Runway East *

*10 Finsbury Square*

*London*

* EC2A 1AF *

On 28 July 2016 at 21:32, Dmitri Gribenko <gribozavr at gmail.com> wrote:

> On Thu, Jul 28, 2016 at 1:27 PM, James Campbell via swift-users
> <swift-users at swift.org> wrote:
> > How are arrays passed to C in Linux ? I tried unwrapping an optional
> array
> > in an if statment and passing it to c. it seemed like the array was
> > deallocated however if I stored it in a local var in the function before
> the
> > if statment it worked perfectly fine, sureley this shouldn't work either
> ?
>
> Would you mind pasting the code example?
>
> 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>*/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160729/34d25903/attachment.html>


More information about the swift-users mailing list