2011-03-04 24 views
2

なぜ変数を宣言しているときに無効な関数宣言があるのか​​分かりません。また、私のtypedefがうまくいかなかった理由は分かりません。typedefと関数宣言のエラー

 
[email protected] 388> g++ -Wall -pthread testHashT.cpp -o testHashT 
memHashT.h:22: error: invalid function declaration 
memHashT.h: In function âvoid memAccessUpdate(void*, unsigned int, pthread_t, bool)â: 
memHashT.h:114: error: cannot convert âmList*â to âlinkedMlist*â in assignment 
memHashT.h:119: error: cannot convert âlinkedMlist*â to âmList*â in assignment 
memHashT.h:128: error: âcountWSâ was not declared in this scope 
memHashT.h:133: error: âcountRAâ was not declared in this scope 
[email protected] 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-> 
} 

私はこれらのエラーを得ている理由としては非常に混乱しています。どんな助けもありがとうございます。 (ヘッダーに関数を宣言するのは良い習慣ではないが、今のところ私は構文を修正しようとしている)。

+0

あなたの質問に答えることはできませんが(これはMacOS X端末からのものと仮定します)、** Terminal-> Preferences-> Settings-> Advancedを設定すると - >文字エンコーディング** to ** Unocode(UTF-8)**、 'â'が引用文字として出力されるので、コンパイラからの出力がより読みやすくなります。 – Lindydancer

答えて

5

がそれを手に入れた見ることができます!私の視力では何時間かかかりました...ライン22の最後の文字を注意深く見てください:-)

また、linkedMlistまたはlinkedM_listと呼ぶかどうかを決めてください。

+0

Ohh wow、ありがとう:) – technaj

+0

なぜそれがコンパイラに関数宣言のように見えますが、私は知らない! –

+0

@Charles: 'C++'のものでなければなりません:) – pmg

2

struct linkedMlistが定義または宣言されていない、限り私は

struct linkedM_list { 
    void * memAddr; 

    //Details 
     bool shared; 
     pthread_t prevThread; 
     unsigned long long rCounter; 
     unsigned long long wCounter; 
    //End Details 
    struct linkedMlist * nextM;    // <===== HERE 
}; 
+0

小さな愚かなエラーを作るとき、おかげで、私はそれが嫌い... – technaj