'p' was declared as a different kind of symbol
Hey everyone, this is my first time posting on the forums. My program is spitting out this error when I try to compile; 'p' was declared as a different kind of symbol. And it also gives me a warning "assignment makes integer from pointer without cast". Error is referring to line 52
Code:
#include <stdlib.h>
#include "multilevelQueueScheduler.h"
void attemptPromote( schedule *ps );
/* initializeSchedule
* input: none
* output: a schedule
*
* Initialize and return a schedule struct.
*/
schedule* initializeSchedule( ) {
schedule *ps = malloc( sizeof(schedule) );
/* TODO: initialize data in schedule */
ps->underExecP = NULL;
ps->fgQ = createQueue();
ps->bgQ = createQueue();
return ps;
}
/* unfinishedSchedule
* input: a schedule
* output: bool (true or false)
*
* Check if there are any processes still in the queues.
* Return TRUE if there is. Otherwise false.
*/
bool unfinishedSchedule( schedule *ps ) {
/* TODO: check if there are any process still in a queue. Return TRUE if there is. */
if(isEmpty(ps->fgQ) && isEmpty(ps->bgQ) && ps->underExecP == NULL){
return false;
}
return true;
}
/* scheduleProcess
* input: a schedule, a string, an int, a priority
* output: void
*
* Create a new process with the provided name, runtime, and priority.
* Add that process to the appropriate queue
*/
void scheduleProcess( schedule *ps, char *functionName, int runtime, priority p ) {
/* TODO: complete this function.
The function "initializeProcessData" in processSimulator.c will be useful in completing this. */
//initialize the process data
processData *data = initializeProcessData(functionName);
//allocate memory for the process
process *p = malloc(sizeof(process));
//initialize the process parameters
strcpy(p->id,functionName);
p->totalCycles = runtime;
p->priority = p;
p->data = data;
p->cyclesOver = 0;
p->waitTime = 0;
//if the process is FOREGROUND
if(p == FOREGROUND){
//enqueue to the foreground queue
enqueue(ps->fgQ,p);
}
else{
//enqueue to the background queue
enqueue(ps->bgQ,p);
}
}
/* simulateTimeStep
* input: a schedule
* output: a string
*
* Use the schedule to determine the next process to run.
* If process being run starts a new process it will return a string.
* This function should just return this string.
*/
char* simulateTimeStep( schedule *ps ) {
/* TODO: complete this function.
The functions "runProcess", "freeProcessData", and "promoteProcess" in processSimulator.c will be useful in completing this. */
if(ps->underExecP != NULL && ps->underExecP->priority == BACKGROUND && !isEmpty(ps->fgQ)){
enqueue(ps->bgQ,ps->underExecP);
ps->underExecP = NULL;
}
//if there isnt any process under execution
if(ps->underExecP == NULL){
//if foreground queue isn't empty
if(!isEmpty(ps->fgQ)){
//dequeue a process from the foreground queue
ps->underExecP = dequeue(ps->fgQ);
}
//if foreground queue is empty but background queue isn't
else if(!isEmpty(ps->bgQ)){
//dequeue a proces from the background queue
process *p = dequeue(ps->bgQ);
//enqueue it to the end of the foreground queue
ps->underExecP = p;
}
else{
//both queue are empty return null
return NULL;
}
}
//if there are processes in background queue
if(!isEmpty(ps->bgQ)){
process *p = getNext(ps->bgQ);
if(p->waitTime != 0 && p->waitTime % MAX_BACKGOUND_WAIT_TIME == 0){
promoteProcess(p->data->name,p->data);
enqueue(ps->fgQ,dequeue(ps->bgQ));
}
p->waitTime++;
}
//since current forgroud process is now set
//run process for a single time step
char *name = runProcess(ps->underExecP->data->name,ps->underExecP->data);
//increment executed cycle
ps->underExecP->cyclesOver ++;
//if executed cycle == total cycles
if(ps->underExecP->totalCycles == ps->underExecP->cyclesOver){
//free process data
freeProcessData(ps->underExecP->data);
//no current process to execute
ps->underExecP = NULL;
}
//if there is a current process but it executed for 5 cycles (round robin)
if( ps->underExecP != NULL && ps->underExecP->cyclesOver % 5 == 0){
//enqueue the current process to the forground queue
enqueue(ps->fgQ,ps->underExecP);
//set current process as null
ps->underExecP = NULL;
}
//return the output of runProcess
return name;
}
/* freeSchedule
* input: a schedule
* output: none
*
* Free all of the memory associated with the schedule.
*/
void freeSchedule( schedule *ps ) {
/* TODO: free any data associated with the schedule. */
if(ps->underExecP != NULL)
free(ps->underExecP);
freeQueue(ps->fgQ);
freeQueue(ps->bgQ);
free(ps);
}
Code:
#ifndef _multilevelQueueScheduler_h#define _multilevelQueueScheduler_h
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include "process.h"
#include "queue.h"
#include "processSimulator.h"
#define MAX_BACKGOUND_WAIT_TIME 50
typedef enum priority { FOREGROUND, BACKGROUND } priority;
/* struct schedule (only accessed in student written code)
*
* Data related to the order the processes should be scheduled in.
* At minimum it should store the FOREGROUND and BACKGROUND queues.
*/
typedef struct schedule
{
//TODO: Put the data for your schedule program here!
process *underExecP;
Queue *fgQ;
Queue *bgQ;
} schedule;
schedule* initializeSchedule( );
bool unfinishedSchedule( schedule *ps );
void scheduleProcess( schedule *ps, char *functionName, int runtime, priority p );
char* simulateTimeStep( schedule *ps );
void freeSchedule( schedule *ps );
#endif
I would appreciate any kind of insight as to where the issue may lie. If you would like to see the other files, please let me know.