当我尝试释放我创建的元组数组时,我收到此错误.
这是发生错误的地方:
void free_freq_words(Tuple *freq_words, int num)
{
int i;
for (i = 0; i < num; i++)
{
free(freq_words[i].word);
free(freq_words[i]); /******* error here *********/
}
}
Run Code Online (Sandbox Code Playgroud)
我创建了这样的元组数组:
Tuple *freq_words = (Tuple *) malloc(sizeof(Tuple) * num);
Run Code Online (Sandbox Code Playgroud)
以下是元组的定义方式:
typedef struct Tuple
{
int freq;
char *word;
} Tuple;
Run Code Online (Sandbox Code Playgroud)
请注意,我非常确定在释放元组之前我必须释放单词,因为我为每个单词分配了空格:
freq_words[num - 1].word = (char *) malloc(sizeof(char) * strlen(word) + 1);
Run Code Online (Sandbox Code Playgroud)
我得到的错误是第二个免费:
fw.c: In function âfree_freq_wordsâ:
fw.c:164:7: error: incompatible type for argument 1 of âfreeâ
free(freq_words[i]);
^
In file included from fw.c:3:0: …Run Code Online (Sandbox Code Playgroud) 我有这个程序,我正在为学校工作,其目的是将两个矩阵相加并将它们的结果存储在第三个矩阵中。目前,与驱动程序一起运行时的指令数为1,003,034,420条(即.o文件),但需要在10亿条以下。但是,我不知道该怎么做,因为我已经考虑了我使用的所有说明,并且所有这些说明似乎都是让程序正常工作的强制性要求。
请注意,此时我无法减少循环展开的指令数量,因为稍后会出现。
这是程序:
/* This function has 5 parameters, and the declaration in the
C-language would look like:
void matadd (int **C, int **A, int **B, int height, int width)
C, A, B, and height will be passed in r0-r3, respectively, and
width will be passed on the stack. */
.arch armv7-a
.text
.align 2
.global matadd
.syntax unified
.arm
matadd:
push {r4, r5, r6, r7, r8, r9, r10, r11, lr}
ldr r4, [sp, #36] @ load width into r4 …Run Code Online (Sandbox Code Playgroud)