Objective-C隐式转换会失去整数精度(将size_t转换为CC_Long) [英] Objective-C Implicit conversion loses integer precision (size_t to CC_Long)

查看:138
本文介绍了Objective-C隐式转换会失去整数精度(将size_t转换为CC_Long)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个函数可以生成字符串的sha256加密,

I have a function that's generating a sha256 encryption of a string,

功能如下:

    -(NSString*)sha256HashFor:(NSString*)input
{
    const char* str = [input UTF8String];
    unsigned char result[CC_SHA256_DIGEST_LENGTH];
    CC_SHA256(str, strlen(str), result);

    NSMutableString *ret = [NSMutableString stringWithCapacity:CC_SHA256_DIGEST_LENGTH*2];
    for(int i = 0; i<CC_SHA256_DIGEST_LENGTH; i++)
    {
        [ret appendFormat:@"%02x",result[i]];
    }
    return ret;
}

现在此行在这里CC_SHA256(str, strlen(str), result);是产生此警告的内容(该警告是针对strlen(str)变量的.)

Now this line right here CC_SHA256(str, strlen(str), result); is what's producing this warning (the warning is for the strlen(str) variable).

Implicit conversion loses integer precision: 'size_t' (aka 'unsigned long') to 'CC_LONG' (aka 'unsigned int')

我猜我只需要将strlen(str)转换为CC_Long,但是我不知道该怎么做.

I'm guessing I just need to convert the strlen(str) to a CC_Long, but I have no idea how to do that.

推荐答案

  1. 大概不是错误,而是警告.

  1. Presumably that's not an error but a warning.

我只需要将strlen(str)转换为CC_Long,但是我不知道该怎么做." -显式类型转换(类型转换):(CC_LONG)strlen(str),但我认为您并不是真的需要它.

"I just need to convert the strlen(str) to a CC_Long, but I have no idea how to do that." - explicit type conversion (type casting): (CC_LONG)strlen(str), but I don't think you really need this.

这篇关于Objective-C隐式转换会失去整数精度(将size_t转换为CC_Long)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆