#16
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    33
    Rep Power
    0
    Originally Posted by ptr2void
    Fix those warnings before you go any further.

    I don't know Pelles, so I can't tell you how to copy and paste the stack trace.

    Relevant links:
    http://forum.pellesc.de/index.php?topic=4283.0
    http://cboard.cprogramming.com/c-programming/131377-help-debugging-pelles-c-ide.html
    I have fixed all warnings but the following two:
    warning #2117: Old-style function definition for 'main'.
    warning #2117: Old-style function definition for 'initSystem'.
    I am really not sure how to fix these.
    Regarding the debugger's output, please explain to me what type of information you need in order to assist me in tracking down what's causing my program to crash and I will make sure to paste it directly from the debugger or to manually type it here based on the debugger's output.
  2. #17
  3. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,145
    Rep Power
    2222
    Originally Posted by peripatein
    I have fixed all warnings but the following two:
    warning #2117: Old-style function definition for 'main'.
    warning #2117: Old-style function definition for 'initSystem'.
    I am really not sure how to fix these.
    Neither are we, unless you expect us to be able to read your mind!

    Why don't you post the code here so that you can stop preventing getting an answer?


    PS
    It might have something to do with a semicolon between the function header and the function's open brace.
    Last edited by dwise1_aol; June 13th, 2013 at 01:03 PM.
  4. #18
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    33
    Rep Power
    0
    I have posted these two functions, but I shall gladly post it again:
    Code:
    int main(){
    	int choice = 0, priority = 0, specific = 0;
    	char name[101];
    	TaxiSystem *sysptr = initSystem();
    	while (choice != 4){
    		printf("Please enter your choice: 1)Add driver 2)Add order 3)Print system 4)Exit\n");
    		scanf("%d", &choice);
    		if (choice == 1){
    			printf("Please enter name and priority\n");
    			scanf("%s", name);
    			scanf("%d", &priority);
    			if (!addDriver(sysptr, name, priority))
    				break;
    		}
    		if (choice == 2){
    			printf("Is the driver specific (please enter 1/0)?\n");
    			scanf("%d", &specific);
    			if (specific){
    				printf("Please enter the driver's name\n");
    				scanf("%s", name);
    				addOrder(sysptr, specific, name);
    			}
    			addOrder(sysptr, specific, NULL);	
    		}		
    		if (choice == 3)
    			printSystem(sysptr);
    	}
    	freeSystem(sysptr);
    	return 0;
    }
    TaxiSystem* initSystem(){
    	TaxiSystem *new_node = NULL;
    	new_node = (TaxiSystem*) malloc(sizeof(TaxiSystem));
    	if (new_node == NULL){
    		printf("Fatal error: memory allocation failed!\n");
    		return NULL;
    	}
    	new_node->numOrder = 0;
    	new_node->driversQueue = NULL;
    	new_node->ordersQueue = NULL;
    	return (new_node);
    }
    Mind you that these warnings are most likely not why the program crashes as I try to add a driver or an order.
    Having posted the code, I shall look forward to perhaps finally realising what is amiss.
  6. #19
  7. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,145
    Rep Power
    2222
    To explain what an "Old-style function definition" is, remember that the ANSI standard for C wasn't published until 1989. That standard established the function definition that we now use. Before ANSI C, the only "standard" was a de facto one established by the first edition of Kernighan and Ritchie's book, The C Programming Language -- Dennis Ritchie designed C; the second edition of the book is still in print and covers ANSI C. As a result, that pre-ANSI style of C is commonly called "K&R C".

    This is what a function definition looked like in K&R C (taken from actual code still posted on the Web, but with the comments removed):
    Code:
    int relativity( p, q, e )
        double p[];
        double q[], e[];
    {
    In ANSI C, that would be:
    Code:
    int relativity( double p[], double q[], double e[] )
    {
    As you can see, in K&R C, only the name of the parameters went into the parameter list and then those names had to be declared between the parameter list and the function body which starts with the open brace. In contrast to that, in ANSI C there cannot be anything but white space between the close parenthesis of the parameter list and the open brace of the function body.

    Therefore, if you do place something other than white space between the close parenthesis of the parameter list and the open brace of the function body, like for example a semicolon from when you copied the function prototype, then the compiler will assume that you're trying to use the old K&R style, which is not allowed. That is what we would expect to find when we get that warning.

    However, I do not see that happening in the code you just listed. Are you sure that you copied and pasted the exact same code that you are getting the warnings for?
    Last edited by dwise1_aol; June 13th, 2013 at 01:27 PM.
  8. #20
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    33
    Rep Power
    0
    Originally Posted by dwise1_aol
    To explain what an "Old-style function definition" is, remember that the ANSI standard for C wasn't published until 1989. That standard established the function definition that we now use. Before ANSI C, the only "standard" was a de facto one established by the first edition of Kernighan and Ritchie's book, The C Programming Language -- Dennis Ritchie designed C; the second edition of the book is still in print and covers ANSI C. As a result, that pre-ANSI style of C is commonly called "K&R C".

    This is what a function definition looked like in K&R C (taken from actual code still posted on the Web, but with the comments removed):
    Code:
    int relativity( p, q, e )
        double p[];
        double q[], e[];
    {
    In ANSI C, that would be:
    Code:
    int relativity( double p[], double q[], double e[] )
    {
    As you can see, in K&R C, only the name of the parameters went into the parameter list and then those names had to be declared between the parameter list and the function body which starts with the open brace. In contrast to that, in ANSI C there cannot be anything but white space between the close parenthesis of the parameter list and the open brace of the function body.

    Therefore, if you do place something other than white space between the close parenthesis of the parameter list and the open brace of the function body, like for example a semicolon from when you copied the function prototype, then the compiler will assume that you're trying to use the old K&R style, which is not allowed.

    However, I do not see that happening in the code you just listed. Are you sure that you copied and pasted the exact same code that you are getting the warnings for?
    The warnings point to the following lines:
    Code:
    "Old-style function definition for 'initSystem'", line 120.
    Line 120: TaxiSystem* initSystem(){
    
    AND
    
    Old-style function definition for 'main', line 46.
    Line 46: int main(){
    I am trying to be as meticulous as possible with my answers here, but I really am not holding any information :-).
    Is it absolutely critical to fix these warnings at this stage? Is it not quite clear that the program crashes due to other reasons, probably related to the implementation of the queues themselves?
    I'd also like to add that a different compiler didn't alert concerning these two issues.
  10. #21
  11. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,145
    Rep Power
    2222
    I do not know the peculiarities of the Pelles compiler. However, of all other users of K&R indenting style that I have seen over the years, none of them have been so eaten up with hiding the open braces that they would also so hide the open brace of the function bodies, not even K&R themselves (I just opened my copy of The C Programming Language, 2nd ed. to verify that).

    Just on the odd chance that your mis-placement of that open brace is confusing Pelles, place the open brace on the next line; ie, try this:
    Code:
    TaxiSystem* initSystem()
    {
        // . . . 
    }
    
    int main()
    {
        // . . . 
    }
    Probably won't do anything, but it couldn't hurt.
  12. #22
  13. No Profile Picture
    I haz teh codez!
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Dec 2003
    Posts
    2,547
    Rep Power
    2337
    Wonder if it's looking for

    Code:
    int main(void){
    and

    Code:
    TaxiSystem *initSystem(void){
    I ♥ ManiacDan & requinix

    This is a sig, and not necessarily a comment on the OP:
    Please don't be a help vampire!
  14. #23
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    33
    Rep Power
    0
    Originally Posted by dwise1_aol
    I do not know the peculiarities of the Pelles compiler. However, of all other users of K&R indenting style that I have seen over the years, none of them have been so eaten up with hiding the open braces that they would also so hide the open brace of the function bodies, not even K&R themselves (I just opened my copy of The C Programming Language, 2nd ed. to verify that).

    Just on the odd chance that your mis-placement of that open brace is confusing Pelles, place the open brace on the next line; ie, try this:
    Code:
    TaxiSystem* initSystem()
    {
        // . . . 
    }
    
    int main()
    {
        // . . . 
    }
    Probably won't do anything, but it couldn't hurt.
    Nope. Alas, warnings persist to plague the code. Would you be so kind as to have a look at some of the other functions? This has become somewhat enigmatic (i.e. why this program crashes) :-).
  16. #24
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    33
    Rep Power
    0
    Originally Posted by peripatein
    Nope. Alas, warnings persist to plague the code. Would you be so kind as to have a look at some of the other functions? This has become somewhat enigmatic (i.e. why this program crashes) :-).
    YES! Void fixed it alright. Not the crashing, though. The warnings. May we please proceed to the prime culprits?
  18. #25
  19. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,145
    Rep Power
    2222
    OK, so are we back to having to do mind-reading tricks?

    Comments on this post

    • ptr2void agrees : Like pulling teeth!
  20. #26
  21. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    33
    Rep Power
    0
    Originally Posted by dwise1_aol
    OK, so are we back to having to do mind-reading tricks?
    I was waiting for your approval :-).

    Code:
    int addDriver(TaxiSystem * system, char * name, int priority){
        /* the function's aim is to add a new driver to the queue.*/
    
        int order;
        int spec;
        /*If the driver already exists, the program does nothing. */
        if (doesDriverExist(system->driversQueue, name))
            return 1;
        /*If the driver is not in the queue, the function is supposed to check whether there is a specific order under his name in the orders' queue, and if so that order is to be released (freed) from the queue. */
        order = findOrderByName(system->ordersQueue, name);
        /* If an order under his name doesn't exist, the drivers' queue is empty and there is specific order to be implemented, the first non specific order is to be released from the queue. */
        if (order){
            EraseOrder(&system->ordersQueue, order);
            return 1;
        }
    	spec = isNotSpecificOrder(&system->ordersQueue);
        /*In case there is no specific order, the driver is to be added to the drivers' queue by priority.*/
        if (system->driversQueue == NULL && spec != 0) 
    		EraseOrder(&system->ordersQueue, spec);
    	return(createDriverAndAddByPriority(system, name, priority));	
    }
    
    int doesDriverExist(Driver * iter, char * name){
        if (iter == NULL)
    		return 0;
        return (strcmp(iter->name, name) == 0 || doesDriverExist(iter->next, name));
    }
    
    int findOrderByName(Order * iter, char * name){
        if (iter == NULL)
    		return 0;
        return (strcmp(iter->specificDriver, name) == 0 ? iter->orderID : findOrderByName(iter->next, name));
    }
    
    void EraseOrder(Order ** iter, int ID){
        Order * cur = *iter, *prv = NULL;
        if (cur->orderID == ID)
    		eraseFirstOrderHelper(iter);
        while (cur->orderID != ID && cur != NULL){
            prv = cur;
            cur = cur->next;
        }
        if (cur != NULL)
    		eraseOrderHelper(prv);
    }
    
    void eraseFirstOrderHelper(Order ** iter){
        Order * tmp = *iter;
        *iter = tmp->next;
        free(tmp);
    }
    
    void eraseOrderHelper(Order * prv){
        Order * tmp = prv->next;
        prv->next = tmp->next;
        free(tmp);
    }
    
    int isNotSpecificOrder(Order ** iter){
    	Order * tmp = *iter;
    	while (tmp->isSpecific && tmp != NULL)
    		tmp = tmp->next;
    	if (tmp == NULL)
    		return 0;
    	return (tmp->orderID);
    }
    
    int createDriverAndAddByPriority(TaxiSystem* system, char* name, int priority){
    	Driver *new_node = NULL, *cur = NULL, *prv = NULL;
    	new_node = (Driver*) malloc(sizeof(Driver));
    	if (new_node == NULL){
    		printf("Fatal error: memory allocation failed!\n");
    		return EXIT_FAILURE;
    	}
    	strcpy(new_node->name, name);
    	new_node->priority = priority;
    	cur = system->driversQueue;
    	if (!cur)
    		cur = new_node;
    	else{
    		while (cur && (cur->priority < new_node->priority)){
    			prv = cur;
    			cur = cur->next;	
    		}
    		new_node->next = cur;
    		prv->next = new_node;
    	}
    	return EXIT_SUCCESS;
    }
  22. #27
  23. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,145
    Rep Power
    2222
    Stupid question.

    In main I noticed this:
    Code:
    		if (choice == 2){
    			printf("Is the driver specific (please enter 1/0)?\n");
    			scanf("%d", &specific);
    			if (specific){
    				printf("Please enter the driver's name\n");
    				scanf("%s", name);
    				addOrder(sysptr, specific, name);
    			}
    			addOrder(sysptr, specific, NULL);	
    		}
    Do you actually intend on adding two orders almost every time you choose to add "an order"? Such that the second order always passes in a NULL for the name? At least, that will happen when you enter a non-zero value for specific. When you try to use an order later on, are you testing for specific being non-zero in order to know whether you can use the name field?

    Did you by any chance intend that to have been something like this?
    Code:
    		if (choice == 2){
    			printf("Is the driver specific (please enter 1/0)?\n");
    			scanf("%d", &specific);
    			if (specific){
    				printf("Please enter the driver's name\n");
    				scanf("%s", name);
    				addOrder(sysptr, specific, name);
    			}
    			else
    				addOrder(sysptr, specific, NULL);	
    		}
    Though of course in the else, then you could call
    addOrder(sysptr, 0, NULL);
    since you would only make that call if specific == 0.

    Just wondering.
  24. #28
  25. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    33
    Rep Power
    0
    Originally Posted by dwise1_aol
    Stupid question.

    In main I noticed this:
    Code:
    		if (choice == 2){
    			printf("Is the driver specific (please enter 1/0)?\n");
    			scanf("%d", &specific);
    			if (specific){
    				printf("Please enter the driver's name\n");
    				scanf("%s", name);
    				addOrder(sysptr, specific, name);
    			}
    			addOrder(sysptr, specific, NULL);	
    		}
    Do you actually intend on adding two orders almost every time you choose to add "an order"? Such that the second order always passes in a NULL for the name? At least, that will happen when you enter a non-zero value for specific. When you try to use an order later on, are you testing for specific being non-zero in order to know whether you can use the name field?

    Did you by any chance intend that to have been something like this?
    Code:
    		if (choice == 2){
    			printf("Is the driver specific (please enter 1/0)?\n");
    			scanf("%d", &specific);
    			if (specific){
    				printf("Please enter the driver's name\n");
    				scanf("%s", name);
    				addOrder(sysptr, specific, name);
    			}
    			else
    				addOrder(sysptr, specific, NULL);	
    		}
    Though of course in the else, then you could call
    addOrder(sysptr, 0, NULL);
    since you would only make that call if specific == 0.

    Just wondering.
    dwise, you're a genius! That 'else' alone already made it run much smoother. It still crashes though once I try to add a driver (but doesn't as I try to add an order), and also does not properly update the respective queue.
  26. #29
  27. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    33
    Rep Power
    0
    Originally Posted by peripatein
    dwise, you're a genius! That 'else' alone already made it run much smoother. It still crashes though once I try to add a driver (but doesn't as I try to add an order), and also does not properly update the respective queue.
    That is not all the program, but it's a huge chunk of it. So once we've covered this we've significantly narrowed it down.
  28. #30
  29. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,145
    Rep Power
    2222
    Well, knowing that the function would make changes to the queue, it just looked odd the way that it was.

    Lunch is over and I have to get back to work now, plus I won't get home until late tonight.

IMN logo majestic logo threadwatch logo seochat tools logo