0

To start off, the goal with my program is to create my own malloc using the buddy allocation scheme. However, when I go to compile my code, I get the initialization from incompatible pointer type error. I am confused on what exactly this means and how I can fix it. Here is a short snippet of the function where this error is occurring:

node *fList[26] = {NULL};

void *divider(int index, int baseCase) {

    node *temporary = fList[index + 1]; 

    int size = ((1 << (index + 6)) / 2);
    node *toSplit =(char *)temporary + size; //where error occurs

    if(temporary->next != NULL) {
        fList[index+1] = temporary->next;
        temporary->next= NULL;
        fList[index+1]->previous = NULL;
    }
    else{
        fList[index+1]=NULL;
    }   

    temporary->next = toSplit;
    toSplit->previous = temporary;

    if(fList[index] != NULL){
        toSplit->next = fList[index];
        fList[index]->previous=toSplit;
    }
    else{
        toSplit->next = NULL;
    }

    fList[index] = temporary;
    temporary->previous=NULL;

    temporary->header = index+5;
    toSplit->header = index+5;


    if(fList[index]->header == baseCase+5){
        fList[index]->header |=128;
        void *tmp = fList[index];
        fList[index]=fList[index]->next;
        if(fList[index]!=NULL)
        {
            fList[index]->previous=NULL;    
        }
        return tmp;
    }
    else{
        divider(index-1,baseCase);
    }
}
1
  • Please provide the full text of the error, which should highlight the line on which it occurs Commented Nov 15, 2015 at 2:57

1 Answer 1

1

Error pretty much says it: you have cast temporary to be a different type of pointer than the variable node that you are trying to assign it to.

As for the incompatability part, there are typically rules for where structs can go in memory (the address has to be a multiple of usually 4 or 8), but chars aren't so restricted, and so you can have a char in a location where a node cannot be.

As for fixing it: cast it to the proper type, and make sure you are generating a valid address for your node.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.