Thread: 'p' was declared as a different kind of symbol

  1. #1
    Registered User
    Join Date
    Nov 2018
    Posts
    3

    '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.

  2. #2
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Code:
    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));
    You are using two different "p" here.
    priority p
    process *p

    I suggest renaming one of them.

    And, you need to post the prototype of initializeProcessData to get help on the message about that line.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  3. #3
    Registered User
    Join Date
    Nov 2018
    Posts
    3
    Thanks for the reply! It actually worked, thank you very much Here's the prototype.
    Code:
    #ifndef _processSimulator_h#define _processSimulator_h
    #include <stdlib.h>
    #include <stdbool.h>
    
    
    #include "process.h"
    
    
    processData* initializeProcessData( char *processName );
    char* runProcess( char *pName, processData* pData );
    void freeProcessData( processData* pData );
    void promoteProcess( char *pName, processData *pData );
    
    
    int max( int a, int b );
    int powInt( int a, int b );
    
    
    #endif
    Last edited by CoolRanch; 11-26-2018 at 07:41 PM.

  4. #4
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    I see no reason for [And it also gives me a warning "assignment makes integer from pointer without cast". Error is referring to line 52 ].
    Maybe, if you fix the name clash of "p" then this message will change or go away.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  5. #5
    Registered User
    Join Date
    Nov 2018
    Posts
    3
    Yeah the warning went away once I changed the name of p. Thank you again for all your help.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 01-10-2012, 08:49 PM
  2. error: ‘y1’ redeclared as different kind of symbol
    By oospill in forum C Programming
    Replies: 7
    Last Post: 11-03-2009, 04:21 PM
  3. Replies: 3
    Last Post: 10-12-2006, 06:58 AM
  4. What kind of job...
    By Discolemonade in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 08-15-2005, 08:23 PM
  5. anyone who is kind?
    By Christine in forum Windows Programming
    Replies: 4
    Last Post: 12-15-2001, 02:55 PM

Tags for this Thread