Hello again,

got myself stuck again with my lack of time between coding c. Gotten myself lost with pointers this time i'm pretty sure.

Declaration in header file

extern DiskRequest proc_new_disk_request(int procnum, int sectornum, ReadOrWrite rw);

Where i'm calling it from and some code around it to make sense

algo_request(int procnum, ReadOrWrite rw, int sectornum)
{
    DiskRequest *new_request;
  
line 151:   new_request = proc_new_disk_request(procnum, sectornum, rw);

...
}

The function itself

DiskRequest proc_new_disk_request(int procnum, int sectornum, ReadOrWrite rw)
{
	DiskRequest *new_request;
	
    new_request = (DiskRequest *) checked_malloc(sizeof(DiskRequest));
    new_request->dr_procnum = procnum;
    new_request->dr_sectornum = sectornum;
    new_request->dr_rw = rw;
    new_request->dr_next = NULL;
    
    return *new_request;
}

The error the compiler is giving me:
disk.c:151: error: incompatible types in assignment

Recommended Answers

All 2 Replies

Change proc_new_disk_reques() to return a pointer and your program should compile

DiskRequest*  proc_new_disk_request(int procnum, int sectornum, ReadOrWrite rw)
{
	DiskRequest *new_request;
	
    new_request = (DiskRequest *) checked_malloc(sizeof(DiskRequest));
    new_request->dr_procnum = procnum;
    new_request->dr_sectornum = sectornum;
    new_request->dr_rw = rw;
    new_request->dr_next = NULL;
    
    return new_request;
}

Note that at some point in the program that pointer has to be free()'ed.

commented: Amazingly fast reply and so helpful in his reply. Thankyou! +2

Thankyou so much for the amazingly fast reply. You guys are so great when it comes to having help on these issues. Thankyou so much

/me adds rep points and will mark as solved


- xyster

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.