我试图让 ac 程序在我的 mac 分区中工作,并且已经想出了大部分的方法,但无法找出一个非常简单的问题。
所以我有一个 .h 文件,我在其中声明了所有变量,并且在我的 .c 文件中我试图运行类似的命令
L2toL1 = (L2_transfer_time)*(L1_block_size);
但是我从来没有得到正确的答案。我在上面的行之前打印变量并且它们打印正确但是当它们相乘时的答案是遥遥无期。那么我怎样才能完成正确的乘法呢?
.h 文件看起来像
#define CONFIG_PARAM 16
#define HIT 1
#define MISS 0
#define TRUE 1
#define FALSE 0
unsigned long long L2=0;
unsigned long long L1=0;
int L1_block_size=0;
int L1_cache_size=0;
int L1_assoc=0;
int L1_hit_time=0;
int L1_miss_time=0;
int L2_block_size=0;
int L2_cache_size=0;
int L2_assoc=0;
int L2_hit_time=0;
extern int L2_miss_time=0;
int L2_transfer_time=0;
int L2_bus_width=0;
int mem_sendaddr=0;
int mem_ready=0;
int mem_chunktime=0;
int mem_chunksize=0;
unsigned long long test;
.c 文件然后运行以下内容并从配置文件中读取特定值 print f 语句的答案应该是 195 但它类似于 49567
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "definitions.h"
int main(int argc, char *argv[]) {
FILE *config_file, *trace;
unsigned int address, exec_info;
char check, trash[25], op;
int j, para;
int i=0;
if(argc >= 2)
config_file = fopen(argv[1],"r");
else
config_file = fopen("config0.txt","r");
// Grabs desired cache parameters from the specified config files
while(fscanf(config_file,"%s %d\n",trash,¶) == 2) {
config[i] = para;
i++;
}
// Close the config file
fclose(config_file);
// Puts Cache parameters from config file in desired variables
InitializeParameters();
/*
unsigned long long L2toL1;
L2toL1 = (L2_miss_time)*(L1_block_size);
printf("L2toL1 is: %Lu\n",L2toL1);
}
int InitializeParameters() {
L1_cache_size = config[0];
L1_block_size = config[1];
L1_assoc = config[2];
L1_hit_time = config[3];
L1_miss_time = config[4];
L2_block_size = config[5];
L2_cache_size = config[6];
L2_assoc = config[7];
L2_hit_time = config[8];
L2_miss_time = config[9];
L2_transfer_time = config[10];
L2_bus_width = config[11];
mem_sendaddr=config[12];
mem_ready=config[13];
mem_chunktime=config[14];
mem_chunksize=config[15];
}
谢谢您的帮助