[swift-users] Ambiguous error for setting a value in a CChar array

Dmitri Gribenko gribozavr at gmail.com
Thu Mar 3 22:46:11 CST 2016


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>*/


More information about the swift-users mailing list