【发布时间】:2020-02-07 22:14:20
【问题描述】:
每当调用函数 initSetArray() 时,我都会收到以下警告:
error: conversion to ‘long unsigned int’ from ‘int’ may change the sign of the result [-Werror=sign-conversion]
setarray = (set*)malloc(sizeof(set) * number_of_sets);
函数 initSetArray 只是简单地初始化 setarray。
void initSetArray(set *setarray, int number_of_sets, int number_of_blocks)
{
setarray = (set*)malloc(sizeof(set) * number_of_sets);
}
我已经定义了两个结构,它们在上面定义的辅助函数中使用:
typedef struct{
uint64_t tag; // For identifying the block
uint8_t valid; // Valid bit for the block
uint8_t dirty; // Dirty bit for the block
} block;
typedef struct{
uint64_t index; // For identifying the set
block* way;
} set;
我无法准确找出哪个变量属于“long unsigned int”类型。我可以做些什么来解决这个问题?
【问题讨论】:
-
不是你的问题,但如果你希望调用者看到分配的
setarray,你需要传递set**而不是set*