- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我不明白为什么它告诉我有一个无效的函数声明,而我只是在声明一个变量。另外,我不明白为什么我的 typedef 不起作用。
Username@Server 388> g++ -Wall -pthread testHashT.cpp -o testHashTmemHashT.h:22: error: invalid function declarationmemHashT.h: In function âvoid memAccessUpdate(void*, unsigned int, pthread_t, bool)â:memHashT.h:114: error: cannot convert âmList*â to âlinkedMlist*â in assignmentmemHashT.h:119: error: cannot convert âlinkedMlist*â to âmList*â in assignmentmemHashT.h:128: error: âcountWSâ was not declared in this scopememHashT.h:133: error: âcountRAâ was not declared in this scope
Username@Server 389> cat memHashT.h
//Basic hash table for memory addresses, recommended size for program running is table indexed by a prime ~81281
/************************************************************
* Structure of table:
* Hash table indexed by memory address
* at each entry a vector made of arrays with size 2 of void pointers
* each vector entry will have the unique memory address and a pointer to a vector
* the vector it points to will contain a list of all threads that accessed that location
*
* Overall:(currently being changed to HT=>LL=>LL
* Hash Table => Vector => Vector Containing threads that accessed a given memory location
*************************************************************/
#include <pthread.h>//same as bellow
#include <stdlib.h>//watch out in case actual function contains this
//using namespace std;
//Global var
unsigned int tableSize; //note this is best if it is a prime number
unsigned long long countWA;
unsigned long long countRA:
unsigned long long countWS;
unsigned long long countRS;
//Linked Lists (thread, then mem)
//added all information in T_list to the M list, can be deleted
/*struct linkedT_list {
int threadID;
struct linkedT_list * nextT;
};
typedef struct linkedT_list tList;
tList * currT, * headT;*/
//For memory addresses
struct linkedM_list {
void * memAddr;
//Details
bool shared;
pthread_t prevThread;
unsigned long long rCounter;
unsigned long long wCounter;
//End Details
struct linkedMlist * nextM;
};
typedef struct linkedM_list mList;
//mList * currM, * headM;
mList ** hashTable;
//computes the index of the hash table
//made its own function in case future implementation need to change how indexing is set up
unsigned int getHTIndex (void * arg){
return (unsigned int) ((unsigned long long)arg%tableSize);
}
//returns pointer to mList containing information
//NOT CORRECTLY IMPLEMENTED YET, NEED TO FIND RIGHT MEM ADDRESS, NOT JUST TOP MEM
mList * getHTElement(void * arg){
mList * tempM;
//tList * tempT = NULL;
unsigned int index = getHTIndex(arg);
tempM = hashTable[index];
//tempT = tempM->threadList;
return tempM;
}
//remove a element
void removeHTElement(void * memArg){
//note no garbage collection yet
;
}
//returns the number of threads to access a memery location
int tLength(void * arg){
return -1;
}
//Create the hash table
int createHashTable(unsigned int num) {
tableSize = num;
hashTable = (mList **) malloc(sizeof(mList) * tableSize);
if (hashTable == NULL)
{
return 0;
//printf("Error: Memory could not be allocated");
}
else {
unsigned int i;
for(i=0;i<tableSize;i++)
{
hashTable[i]=NULL;
}
}
return 1;
}
void destroyHashTable(){
free(hashTable);
}
//adds a element to the hash table
void memAccessUpdate(void * memArg, unsigned int thread, pthread_t thread_id, bool writeAccess){
mList * headM = getHTElement(memArg);
mList * currM;
if (headM == NULL)
{//then create and new mList
currM = (mList *)malloc(sizeof(mList));
//initialize values
currM->shared = false;
currM->prevThread = thread_id;
currM->rCounter = 0;
currM->wCounter = 0;
currM->nextM = hashTable[getHTIndex(memArg)];
hashTable[getHTIndex(memArg)] = currM;
}
else {//change details in linked list and global var
//headM->nextM = (mList *)malloc(sizeof(mList));
currM = headM->nextM;
if (thread_id != currM->prevThread){
currM->shared = true;
currM->prevThread = thread_id;
}
if(writeAccess)
{
countWA++;
if(currM->shared){
countWS++;
}
currM->wCounter++;
}
else{//mem read
countRA++;
if(currM->shared){
countRS++;
}
currM->rCounter++;
}
}
//if (stuff) //possibly don't need
//else
// head = hashTable[index]; //note may be null
// curr = (mList *)malloc(sizeof(mList));
// curr->
}
我很困惑为什么会收到这些错误。任何帮助表示赞赏。 (我知道在 header 中声明函数不是好的做法,但现在我只是想纠正我的语法)。
最佳答案
明白了!费了点功夫,我的眼力……仔细看第22行的最后一个字符:-)
另外,决定是要将其命名为 linkedMlist
还是 linkedM_list
。 (那个并没有那么刺眼。)
关于c++ - typedef 和函数声明错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5195942/
我想“创建”一个类型“my_type”,它是一个 std_logic_vector(...),就像这个 C/VHDL 假代码: typedef std_logic_vector(CONSTANT do
这个问题不太可能帮助任何 future 的访问者;它只与一个小的地理区域、一个特定的时间点或一个非常狭窄的情况有关,这些情况并不普遍适用于互联网的全局受众。为了帮助使这个问题更广泛地适用,visit
我已阅读说明,我明白它是一个函数类型别名。 typedef 或函数类型别名为函数类型提供一个名称,您可以在声明字段和返回类型时使用该名称。当将函数类型分配给变量时,typedef 会保留类型信息。 h
Vala 是否有能力做一些类似于 C 中的 typedef 或 D 中的 alias 的事情?我检查了它的零星文档,但找不到与此相关的任何内容。 最佳答案 不是 typedef 本身,但您可以扩展大多
我对这段代码有一些问题: typedef struct Product { char product_code[5]; int sells; int sells_quantit
我对书中的代码有疑问: const int SQUARE_ARRAY_SIZE = 4; const int SQUARE_INFO_SIZE = 4; typedef Square SquareAr
typedef经常像这样工作:typedef .但是函数指针的 typedef 似乎有不同的结构:typedef int (*fn)(char *, char *); - 没有类型别名,只有一个函
我被分配去处理一些代码,但我事先得到了一部分。它包括这部分代码: typedef int ElementType; struct Node; typedef struct Node *PtrToNod
我正在尝试创建通用容器包装器。 template class ContainerWrapper { public: using allocator_type = typename type::al
抱歉,标题太长了。 我在类列表中有一个 typedef: template class List { // Think of a class Iter_ with ListElem *pCu
我想制作一个 typedef,它依赖于模板参数中 typedef 的存在: struct foo { using MyType = int; }; template struct bar {
出于教育目的,我正在查看 Eigen 源代码。我注意到对于每个具体类模板 X在层次结构中,有一个 internal::traits定义。一个典型的例子可以在 Matrix.h 中找到: namespa
假设我有三个文件 //first.h typedef typename std::map MapVertexVd_t; //the graph class and ... //other useful
如果我需要 Swift 中的自定义类型,我可以 typedef,我该怎么做? (类似于闭包语法 typedef) 最佳答案 关键字typealias用于代替typedef: typealias Cus
由于标题可能看起来很困惑,让我举个例子: typedef bool foo[2]; typedef foo bar[4]; bar what_am_i; 所以,我认为 what_am_i 是 [4][
我想声明一个 typedef,像这样: 指向另一个 typedef 的任何数组的指针。 例如: 类型定义 1: typedef struct { int a; }structA_t1; 类型定
要将 my_int 声明为 int 的类型别名,我们可以这样写: typedef int my_int; // (1) 奇怪的是,以下内容似乎也定义了 int 别名: int typedef my
如何在其他 typedef struct 中声明 typedef struct? typedef struct { char* type; char* destination;
我正在尝试将 malloc'd ptr 保存在全局 ptr 中,以便我可以在另一个函数中使用它。理想情况下,我希望在全局范围内有一个更智能的数据结构,但现在我只是想让全局 ptr 工作。 在我的 lw
MachineState machine; ControlSignals theControls = machine.control_signals; //Why is this giving an
我是一名优秀的程序员,十分优秀!