Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4021284
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:19:58+00:00 2026-05-20T10:19:58+00:00

I cannot figure out why g++ is giving the following errors. I believe that

  • 0

I cannot figure out why g++ is giving the following errors. I believe that all the function are declared properly and the braces match up.

(testHashT.cpp just has the header and an empty main)


USERNAME@SERVER 391> 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:78: error: âgetHTElementâ was not declared in this scope
memHashT.h:88: error: âgetHTIndexâ was not declared in this scope
memHashT.h:93: error: cannot convert âlinkedMlist*â to âmList*â in assignment
memHashT.h:102: error: âcountWSâ was not declared in this scope
memHashT.h:107: error: âcountRAâ was not declared in this scope
memHashT.h: In function âmList* getHTElement(void*)â:
memHashT.h:133: error: âgetHTIndexâ 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;
//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->
}

//remove a element

void removeHTElement(void * memArg){
    //note no garbage collection yet
    ;
}

//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;
}

//returns the number of threads to access a memery location
int tLength(void * arg){
    return -1;
}

//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);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T10:19:59+00:00Added an answer on May 20, 2026 at 10:19 am

    You’re using functions before you declare them. For example getHTElement uses getHTIndex which is not declared until afterwards.

    In general, defining functions in headers is almost always wrong. Declare them in headers and define them in source files.

    (You also have numerous errors in your testcase which tells me that the code you posted is not the code you’re using, but it was enough to deduce the above.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A puzzler from a coworker that I cannot figure out... update btd.dbo.tblpayroll set empname
I often work with sales and marketing types that cannot figure out how to
I cannot figure out how to change the title bar icon (the icon in
I cannot figure out a way to disable a container AND its children in
I cannot figure out how to enable per-session instances for my WCF service while
I cannot figure out how to make a C# Windows Form application write to
I've tried my best and cannot figure out what happened here. It worked fine
I have not used generics much and so cannot figure out if it is
I have a WPF ListView which repeats the data vertically. I cannot figure out
I know this is probably really obvious, but I cannot figure out why I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.