LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-09-2009, 04:50 PM   #1
davidstvz
Member
 
Registered: Jun 2008
Posts: 405

Rep: Reputation: 31
Old C program gives error only on new compiler


I'm trying to compile this software called OSP. If you are familiar with it, this is OSP version one (written circa 1990). It compiles fine an this old Sun Solaris server, but on this new server running SUSE Linux 10 I get errors. Here's the command I'm using to compile:

cc -lm -w *.c

I'm probably just using bad command line options causing it to link incorrectly. I'm really rusty on my C code, but I need to get this program working so a professor can teach his OS course.

Here are the errors for the first file (all the remaining errors are similar):

Code:
cpu.c:198: error: static declaration of âfind_highest_priority_pcbâ follows non-static declaration
cpu.c:43: error: previous declaration of âfind_highest_priority_pcbâ was here
cpu.c:249: error: static declaration of âduplicate_pcbâ follows non-static declaration
cpu.c:94: error: previous implicit declaration of âduplicate_pcbâ was here
Here is the section of code containing Line 43 (43 is the last line in this snippet)

Code:
#include   "cpu.h"
#include   "cpu.private.h"

#define NULL           0

#include "ospmasks.h"

#define cost(pcb)       ( pcb->last_dispatch + pcb->last_cpuburst + start_cost(pcb) )

#define is_queue_empty() ( (ready_q.head == NULL) && (ready_q.tail == NULL) ?\
                                        true : false )

extern int    ______trace_switch;
extern int    ______MASK;

extern check_pcb();
extern check_page_table();
extern osp_abort();

PCB  *find_highest_priority_pcb();
Line 94 is the first if statement //i.e. if (!duplicate_pcb(pcb)) {

Code:
PUBLIC
insert_ready(pcb)
PCB *pcb;
{
    READY_Q *new_process;

    /* check PCB pointer */

    check_pcb(pcb,1,"CPU.insert_ready","","upon entering routine");
    if (!duplicate_pcb(pcb)) {
        pcb->status = ready;
        pcb->priority = cost(pcb);
        new_process = (READY_Q *)malloc(sizeof(READY_Q));
        new_process->pcb  = pcb;
        new_process->next = NULL;

       if (is_queue_empty() == true) {  /* is_queue_empty  is a macro  */
           ready_q.head = new_process;
           ready_q.tail = new_process;
       }
       else {
           ready_q.tail->next = new_process;
           ready_q.tail       = new_process;
       }
    }
    else
        printf("CLOCK> %6d#*** WARNING: CPU.insert_ready>\n\t\tTrying to insert duplicate PCB %d; duplicate discarded\n\n\n",get_clock(),pcb->pcb_id);

}  /* insert ready */
And here's how the find_highest_priority_pcb function is written. Line 198 is actually the line with the bracket on it following the function declaration.

Code:
PRIVATE
PCB *find_highest_priority_pcb()
{
    READY_Q  *lowest, *next_rdy, *tmp_ptr;  /* pointer to READY_Q  */
    PCB      *ret_pcb;

    lowest    = ready_q.head;    /* assume head pcb has the lowest cost */
    next_rdy  = ready_q.head;
    while(next_rdy != NULL){
      if (next_rdy->pcb->status != waiting &&
          next_rdy->pcb->priority < lowest->pcb->priority)
          lowest = next_rdy;
      next_rdy = next_rdy->next;
    }

    /* remove the lowest from the ready_q */
    if (lowest == ready_q.head)
        ready_q.head = ready_q.head->next;
    else {
           tmp_ptr = ready_q.head;
           while(tmp_ptr->next != lowest)
                tmp_ptr = tmp_ptr->next;
           if (tmp_ptr->next == ready_q.tail)
               ready_q.tail = tmp_ptr;
           tmp_ptr->next = lowest->next;
    }
    ret_pcb = lowest->pcb;
    free(lowest);
    return(ret_pcb);
}
And finally, here is how the duplicate_pcb function is written (this function doesn't appear in the declarations section)

Code:
PRIVATE
int duplicate_pcb(pcb)
PCB  *pcb;
{
   READY_Q *tmp_ptr;
   int     found;

   found   = FALSE;
   tmp_ptr = ready_q.head;
   while(tmp_ptr != NULL){
      if (tmp_ptr->pcb->pcb_id == pcb->pcb_id)
         found = TRUE;
      tmp_ptr = tmp_ptr->next;
   }
   return(found);
}
Any ideas?
 
Old 02-09-2009, 06:36 PM   #2
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,780

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
I can reproduce this with the following
Code:
int func();

static int func() {
    return 42;
}
cc compiles this, but gcc does not. Putting
Code:
 static int func()
satisfies gcc. I'm guessing PRIVATE is #defined as static. So you'll need:
Code:
PRIVATE PCB  *find_highest_priority_pcb();
// not putting a declaration is like int function_name();
PRIVATE int duplicate_pcb(PCB *pcb);

Last edited by ntubski; 02-09-2009 at 06:37 PM. Reason: simplify: no void in params
 
Old 02-09-2009, 06:45 PM   #3
davidstvz
Member
 
Registered: Jun 2008
Posts: 405

Original Poster
Rep: Reputation: 31
I was hoping to avoid having to edit all the files. Oh well. Where do I need my PRIVATE/static? On both the declarations and the actual function I guess? NM, that is obvious. PRIVATE precedes each function so apparently it needs to precede each declaration as well. At least they should all be in a neat list.

EDIT:

Actually, I just noticed there are files like:

simcore.private.h

I don't see the word PRIVATE defined in any of the files.

Last edited by davidstvz; 02-09-2009 at 07:11 PM.
 
Old 02-10-2009, 01:21 PM   #4
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,780

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
Quote:
I don't see the word PRIVATE defined in any of the files.
It's got to be somewhere.
Code:
grep -R '^#define[ \t]*PRIVATE' *
?

Quote:
I was hoping to avoid having to edit all the files.
If you can find where PRIVATE is #defined, and none of the different PRIVATE functions have the same name, you could get away with not having static in the declaration or definition. Just #define PRIVATE as nothing.
 
Old 02-11-2009, 01:10 AM   #5
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,928

Rep: Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612
Try using the '-ansi' option to the compiler, or '-std=C99'
 
Old 02-11-2009, 09:18 AM   #6
davidstvz
Member
 
Registered: Jun 2008
Posts: 405

Original Poster
Rep: Reputation: 31
Thanks guys, I will try both of these. I was busy all day yesterday with some administrative junk..

grep was my next move for finding the PRIVATE identifier and I thought there might be command line options for running gcc in an older mode for compatibility. Keeping my fingers crossed!

Ok, grep shows that PRIVATE is defined as... you guessed it... static (in three different files: cpu.private.h, files.private.h and memory.private.h ).

First I will try the compatibility options in gcc. I don't think I *can* remove the static identifier. A lot of these functions (this being an OS simulator) redefine things that are already defined which is probably why they are defined as static. Removing the static identifier will probably just give me a different set of errors.

EDIT: maybe I'm wrong about redefining PRIVATE to mean nothing. It's worth a shot anyway.

EDIT2: Darn, the standards change didn't help. Time to try the PRIVATE hack.

Last edited by davidstvz; 02-11-2009 at 10:39 AM.
 
Old 02-11-2009, 10:43 AM   #7
davidstvz
Member
 
Registered: Jun 2008
Posts: 405

Original Poster
Rep: Reputation: 31
Ah crap, that didn't work because while some functions are declared as PRIVATE, some just use regular old "static"

Ok... how is this possible?

Code:
# grep page_in *
simcore.c:              total_num_page_in=0,
simcore.c:              total_num_lock_page_in=0,
simcore.c:       total_num_lock_page_in++;
simcore.c:        page_in(pcb, page_id, frame_id);   /* record that page is in  */
simcore.c:/*                    page_in()                                       */
simcore.c:static page_in(pcb, page_id, frame_id)
simcore.c:            total_num_page_in++;
simcore.c:                                                      total_num_page_in);
simcore.c:                                                      total_num_lock_page_in);
simcore.c:                                                   total_num_page_in
simcore.c:                                                   - total_num_lock_page_in);
page_in isn't even declared anywhere, it's merely called without it even being defined. I didn't know that was even possible, but it explains why it is referred to as an implicit declaration on line 477. Maybe I should just add declarations... although it's a pretty huge list. IF I could grep the lines where static functions are (without getting the lines where static variables are declared) it wouldn't be too hard to patch that in. Here are the errors.

simcore.c:503: error: static declaration of âpage_inâ follows non-static declaration
simcore.c:477: error: previous implicit declaration of âpage_inâ was here

Last edited by davidstvz; 02-11-2009 at 11:00 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
checking for C compiler default output... configure: error: C compiler cannot create fiorejm Linux - Software 6 11-12-2009 12:35 PM
How to tell digitalmars compiler compile program for DOS? cigarstub Programming 1 04-04-2007 08:15 PM
C compiler cannot create execultables ,when I installing netcdf program. cerzza Linux - Desktop 2 11-17-2006 02:02 AM
in gcc compiler error: parse error before string constsnt cynthia_thomas Linux - Networking 1 10-20-2005 01:29 AM
gcc: Internal compiler error: program cc1 got fatal signal 11 smj Linux - Software 2 02-20-2003 10:35 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:25 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration