[swift-users] Ambiguous error for setting a value in a CChar array
Adam Campbell
adam.92.ac at gmail.com
Thu Mar 3 22:50:43 CST 2016
Thanks Dmitri,
Does the first statements I posted without .value compile at this time?
Or give a better error than I was receiving?
Adam
On Fri, Mar 4, 2016 at 3:46 PM Dmitri Gribenko <gribozavr at gmail.com> wrote:
> On Thu, Mar 3, 2016 at 7:54 PM, Adam Campbell via swift-users
> <swift-users at swift.org> wrote:
> > Discovered this when trying to answer a stackoverflow question about
> setting
> > character values in a CCString array.
> >
> > The following code produces an ambiguous error:
> > var buff = [CChar](count: 5, repeatedValue: 0)
> > buff[0] = "A".utf8.first!.value // Error - Cannot assign value of type
> > 'Int8' to type 'CChar' (aka 'Int8')
> >
> > I can easily get around this by changing the second line to:
> > buff[0].value = "A".utf8.first!.value
> >
> > Can someone explain what is happening here? As well as the significance
> of
> > Int8.value?
>
> The 'var value' property used to be a property of type Builtin.Int8,
> which maps directly to LLVM's i8. This is a part of the integers
> implementation, and it was renamed to 'var _value' a while ago.
> Please don't use this property. The code that you posted (that
> accesses '.value') does not compile anymore.
>
> 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/20160304/bdf98d65/attachment.html>
More information about the swift-users
mailing list