我正在编写一个C函数来模拟给定地址跟踪的缓存.使用gcc(真正的铿锵)在我的mac上编译时,该函数按预期工作.gcc --version在我的Mac上返回:
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 8.1.0 (clang-802.0.42)
Run Code Online (Sandbox Code Playgroud)
当我使用gcc在linux上编译相同的程序时,返回是关闭的,我的程序中的eC&hC(缓存逐出计数器和命中计数器)是数十万,当它们应该低于10.当键入gcc时 - -version在linux机器上,它返回:
gcc(Ubuntu 4.9.3-8ubuntu2~14.04)4.9.3
这是程序:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#include <getopt.h>
#include "cachelab.h"
typedef struct{
int v;
int t;
int LRU;
} block;
typedef struct{
block *blocks;
} set;
typedef struct{
set *sets;
} cache;
void simulate(int s, int E, int b, char* file, int* hC, int* mC, int* eC)
{
int numSets = (1 << s);
char operation;
int …Run Code Online (Sandbox Code Playgroud)