2014-09-29 51 views
0

为了获得向量和并行化的感觉我目前正尝试使用VC(http://code.compeng.uni-frankfurt.de/projects/vc)并行化我的程序。我的程序是用C编写的,但VC需要使用C++。所以我将我的文件重命名为.cpp并试图编译它们。我得到三个编译我怎么能解决这个问题得到了C++编译器的工作我的代码都是一样的C++从'void *'无效转换为'crypto_aes_ctx *'

error: invalid conversion from ‘void*’ to ‘crypto_aes_ctx*’ 

代码如下

int crypto_aes_set_key(struct crypto_tfm *tfm, const uint8_t *in_key, 
    unsigned int key_len) 
{ 
    struct crypto_aes_ctx *ctx = crypto_tfm_ctx(tfm); 
    uint32_t *flags = &tfm->crt_flags; 
    int ret; 
    ret = crypto_aes_expand_key(ctx, in_key, key_len); 
    if (!ret) 
     return 0; 

    *flags |= CRYPTO_TFM_RES_BAD_KEY_LEN; 
    return -EINVAL; 
} 

错误?

回答

3

在C++中键入比C更严格,所以你必须使用cast来告诉编译器void指针实际是什么。

struct crypto_aes_ctx *ctx = (struct crypto_aes_ctx*) crypto_tfm_ctx(tfm); 

请注意,我使用的是C风格的演员,如果你想继续与C的代码对于C++,你会以其它方式使用reinterpret_cast

2

在C++中,您可能不会将类型为void *的指针指定给其他类型的任何其他指针,而无需进行明确的重新解析转换。

如果语句时发生错误

struct crypto_aes_ctx *ctx = crypto_tfm_ctx(tfm); 

,那么你必须写

struct crypto_aes_ctx *ctx = reinterpret_cast<struct crypto_aes_ctx *>(crypto_tfm_ctx(tfm)); 
相关问题