0

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

2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by xyster
1

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.

Votes + Comments
Amazingly fast reply and so helpful in his reply. Thankyou!
0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.