compile prob

This is a discussion on compile prob within the C Programming forums, part of the General Programming Boards category; hey every one.. i get these error msgs with my code.. i just dont get.. it.. am i missing something ...

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    18

    compile prob

    hey every one.. i get these error msgs with my code.. i just dont get.. it.. am i missing something

    Code:
    cc -o clock clock.c clock.h
    cc: Error: clock.c, line 76: In this statement, "free_list_head" is not declared. (undeclared)
            free_list_head = (list)malloc(sizeof(struct list_item));
    --------^
    cc: Error: clock.c, line 97: In this statement, "total_ref" is not declared. (undeclared)
                    total_ref++;
    ----------------^
    cc: Error: clock.c, line 151: In this statement, "free_list_head" is not declared. (undeclared)
            if (free_list_head == free_list_head->prev)   /* free list empty */
    ------------^
    cc: Error: clock.c, line 245: In this statement, "total_ref" is not declared. (undeclared)
            printf("\nProcess issued %d memory references\n", total_ref);
    ----------------------------------------------------------^
    Code:
    #include "clock.h"
    
    
    pt_entry pte[MAX_PAGE];                         /* page table */
    int mem_size;                                           /* physical memory size
    list free_list_head;                            /* free list */
    list res_set_head;                                      /* resident set */
    int total_fault = 0;                            /* total number of page faults
    int total_ref = 0;                                      /* total number of memo
    
    /* main program:
    ** read in paramters, and open the input file
    ** start the simulation
    ** close the input file
    */
    int main(int argc, char *argv[])
    {
            FILE *stream;
    
            if (argc != 3)
            {
                    printf("The format is: pager file_name memory_size.\n");
                    exit(1);
            }
    
            printf("File used %s, resident set size %d\n", argv[1], atoi(argv[2]));  
            if ((stream = fopen(argv[1], "r")) == NULL)
            {
                    perror("File open failed");
                    exit(1);
            }
    
            mem_size = atoi(argv[2]);
            start_simulation(stream);
            fclose(stream);
    }
    
    /* start_simulation:
    ** initialise the page table
    ** initialise the resident set, and the free list
    ** in the simulation loop
    **              16-bit memory addresses representing the program trace are read
    **              the virtual address is resolved ie. physical frame for the virt
    **              the loop exits when it encounters the end of file
    ** free memory allocated for lists
    ** display statistics
    */
    void start_simulation(FILE * stream)
    { 
    
            char *addr_buf;
            int address;
            int i, n;
            list new_entry, current;
    
    /* initialise the page table */
    
            for(i=0; i<MAX_PAGE;i++)
            {
                    pte[i].frame = -1;
                    pte[i].valid = 0;
                    pte[i].dirty = 0;
                    pte[i].in_mem = 0;
                    pte[i].R = 0;
            }
    
    
    /* initialise the resident set - empty*/
    
            res_set_head = (list)malloc(sizeof(struct list_item));
            res_set_head->next = res_set_head;
            res_set_head->prev = res_set_head;
    
    /* initialise free list - all physical pages*/
    
            free_list_head = (list)malloc(sizeof(struct list_item));
            free_list_head->next = free_list_head;
            free_list_head->prev = free_list_head;
            current = free_list_head;
    
            for(i=0; i<mem_size;i++)
            {
                    new_entry = (list)malloc(sizeof(struct list_item));
                    current->next = new_entry;
                    new_entry->prev = current;
                    new_entry->next = free_list_head;
                    new_entry->frame = i;
                    current = new_entry;
                    free_list_head->prev = current;
            }
    
    /* main simulation loop */
    
            while( (n = fscanf(stream, "%x", &address)) != -1)
            {
                    resolve(address);
                    total_ref++;
            }
    
            free_mem(free_list_head);
            free_mem(res_set_head);
            display_stats();
    
            return;
    }
    
    /* resolve:
    ** resolve address reference
    **              if page table entry valid - do nothing
    **              if page table entry invalid - find a physical frame for this pa
    **              and update pte for the page
    */
    void resolve(int address)
    { 
            unsigned short frame_alloc;
            int virt_page;
            static int disp_counter = 0;
     
            virt_page = address >> 8;
            if (pte[virt_page].valid == 1)
            { 
    
            /* depending on the algorithm used you may need to manipulate various
               fields in the page table entry for the page
            */
            pte[virt_page].R = 1;
    
            }
            else
            {
    
                    frame_alloc = find_frame();
                    pte[virt_page].valid = 1;
                    pte[virt_page].frame = frame_alloc;
                    pte[virt_page].R = 1;
                    total_fault++;
            }
    }
    
    /* find_frame:
    **              if free list is empty find a victim frame
    **              else detach the last frame of the free list and attach it
    **              to the resident set
    **              return frame number
    */
    unsigned short find_frame()
    {
            unsigned short frame;
            list current, new_tail;
    
            if (free_list_head == free_list_head->prev)   /* free list empty */
                    frame = find_victim();
            else
            {
                    new_tail = free_list_head->prev->prev;
                    new_tail->next = free_list_head;
                    current = free_list_head->prev;
                    free_list_head->prev = new_tail;
    
                    to_resident_set(current);
                    frame = current->frame;
            }
            return frame;
    }
    
    /* to_resident_set:
    **              attach a list entry at the end of resident set
    */
    void to_resident_set(list current)
    {
            list tail;
    
            tail = res_set_head->prev;
            tail->next = current;
            current->next = res_set_head;
            current->prev = tail;
            res_set_head->prev = current;
    }
    
    
    /* find_victim:
    ** As you can see I simply take the first page frame from the resident set list
    ** This implements the FIFO replacement strategy. Your task is to replace it wi
    ** a more efficient strategy.
    */ 
    unsigned short find_victim()
    { 
            unsigned short frame;
            //list current;
            int i, found = 0;
            static list curr = NULL;
    
            if(curr == NULL)
                    curr = res_set_head;
    
            while(found != 1)
            {
                    frame = curr->frame;
    
                    for(i=0; i<MAX_PAGE; i++)
                    {
                            if(pte[i].frame == frame && pte[i].R == 0)
                            {
                                    found = 1;
                                    pte[i].valid = 0;
                                    pte[i].frame = -1;
                                    pte[i].R = 0;
                                  //printf("\n Page %X is evicted\n", i);
                                    break;
                            }
                            else
                                    pte[i].R = 0;
                    }
                    curr = curr->next;
            }
            return frame;
    }
    
    /* invalidate:
    ** invalidate the page table entry for the victim page
    */
    void invalidate(unsigned short frame)
    {
            int i;
    
            for(i=0;i<MAX_PAGE;i++)
            {
                    if (pte[i].frame == frame && pte[i].valid == 1)
                    {
                            pte[i].valid = 0;
                            pte[i].frame = -1;
                            break;
                    }
    
            }
    } 
    
    /* display_stats:
    ** This is very basic, you may want to make it more sophisticated,
    ** for example save the data from multiple runs into a file for
    ** comparison etc
    */
    void display_stats()
    {
            printf("\nProcess issued %d memory references\n", total_ref);
            printf("Process triggered %d page faults\n", total_fault);
            printf("Page fault rate is %d percent\n",((total_fault*100)/total_ref));
    }
    
    /* free_mem:
    ** free memory allocated to the list
    */
    void free_mem(list head)
    {
    
            list current,tail;
    
            tail = head->prev;
            current = head;
    
            while (current->prev != tail)
            {
                    current = current->next;
                    free(current->prev);
            }
    }

  2. #2
    Registered User Draco's Avatar
    Join Date
    Apr 2002
    Posts
    463
    which compiler are you using? Try it without putting clock.h in the compile command line.

  3. #3
    Registered User
    Join Date
    Sep 2002
    Posts
    18
    i get the same error..
    im using cc -o compiler..via ssh secure shell...

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    1) don't compile header files directly.

    2) Look at the 3rd line of code in what you' ve posted. Is there something missing from the end of the line? To be clear, it's the one starting "int mem_size;". There are also other examples of the same problem.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  5. #5
    Registered User
    Join Date
    Sep 2002
    Posts
    18
    thanks.. it was the comments
    thakns

  6. #6
    Registered User jcramer's Avatar
    Join Date
    Oct 2003
    Posts
    23
    This is sort of off topic but, I just installed Red Hat 9 on my PC, and I use gcc compiler to work on my C programming homework.

    I compile a test program that says "Hello World", gcc compiles it, and returns me to the command prompt.

    However, when i type in the name of the program, it just goes back to the command prompt, doesnt give me any kind of "command not found" error, just returns to prompt.

    The gcc compiler works as far as I can tell, it outputs an executable, but when you got to run the program, (double-clicking on the file in Kde) Nothing happens.

    my program is called test

    This is how I ran the compiler:

    prompt> gcc -Wall test.c -o test

    I do this at a computer at the University that I go to, and it outputs the program, and when i run it, it works. But on my home machine, it compiles, but does not run.

    This is the program I compiled and tried to run...

    Code:
    #include <stdio.h>
    
    int
    main(void)
    {
    
    printf( "Hello World\n" );
    
    return(0);
    
    }

  7. #7
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,498
    @jcramer
    Please start a new thread if its a new topic. Random off-topic replied to other peoples threads are not helpful.

    > prompt> gcc -Wall test.c -o test
    test is the name of an existing unix utility program

    prompt > test
    This runs the standard one

    prompt > ./test
    This runs the one you just compiled.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compile as you type
    By Rocketmagnet in forum A Brief History of Cprogramming.com
    Replies: 33
    Last Post: 12-07-2006, 12:36 PM
  2. How to compile mfc libs from platform sdk
    By tjcbs in forum Windows Programming
    Replies: 6
    Last Post: 11-19-2006, 07:20 AM
  3. Compile crashes certain windows
    By Loduwijk in forum C++ Programming
    Replies: 5
    Last Post: 03-26-2006, 08:05 PM
  4. open scene graph compile issues
    By ichijoji in forum Game Programming
    Replies: 1
    Last Post: 08-04-2005, 12:31 PM
  5. How can I compile C or C++ with Visual Studio .NET?
    By Dakkon in forum C Programming
    Replies: 8
    Last Post: 02-11-2003, 01:58 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21