Help for the c error

This is a discussion on Help for the c error within the C Programming forums, part of the General Programming Boards category; I am having an annoy problem with errors: processor.c:22: called object is not a function processor.c:24: called object is not ...

  1. #1
    Registered User
    Join Date
    May 2004
    Posts
    6

    Help for the c error

    I am having an annoy problem with errors:

    processor.c:22: called object is not a function
    processor.c:24: called object is not a function
    processor.c:26: called object is not a function
    processor.c:28: called object is not a function
    processor.c:30: called object is not a function
    processor.c:32: called object is not a function
    processor.c:34: called object is not a function
    processor.c:36: called object is not a function
    processor.c:38: called object is not a function
    processor.c:40: called object is not a function
    processor.c:42: called object is not a function
    processor.c:44: called object is not a function

    The processor.c 's source code is like this:


    #include <stdio.h>
    #include "memory.h"
    #include "processor.h"
    #include "Instructions.h"

    void execute(void)
    {
    int instructionRegister = 0;
    int instruction = 0;
    int operand = 0;
    accumulator = 0;
    instructionCounter = 0;
    while(instructionCounter<size)
    {
    instructionRegister = readMemory(instructionCounter);
    ++instructionCounter;
    instruction = instructionRegister/100;
    operand = instructionRegister%100;
    switch(instruction)
    {
    case read: read(operand);
    break;
    case write: write(operand);
    break;
    case load: load(operand);
    break;
    case store: store(operand);
    break;
    case add: add(operand);
    break;
    case substract: substract(operand);
    break;
    case divide: divide(operand);
    break;
    case multiply: multiply(operand);
    break;
    case branch: branch(operand);
    break;
    case branchNeg: branchNeg(operand);
    break;
    case branchZero: branchZero(operand);
    break;
    case halt: halt();
    break;
    }
    }
    }

    All those "read", "write", "load" , ... functions are declared in the header file "Instructions.h". The Instruction.h is like following:

    #define read 10
    #define write 11
    #define load 20
    #define store 21
    #define add 30
    #define substract 31
    #define divide 32
    #define multiply 33
    #define branch 40
    #define branchNeg 41
    #define branchZero 42
    #define halt 43

    void read(int);
    void write(int);
    void load(int);
    void store(int);
    void add(int);
    void substract(int);
    void divide(int);
    void multiply(int);
    void branch(int);
    void branchNeg(int);
    void branchZero(int);
    void halt(void);

    I really can't see why the compiler can't recognise all the functions in the Instruction.h header file???

  2. #2
    Registered User
    Join Date
    May 2004
    Posts
    127
    The preprocessor performs textual replacement before anything else is done with the source code. That means all occurances of read, write, etc. will be replaced with integer literals. As an example, the following
    Code:
    case read: read(operand);
    becomes
    Code:
    case 10: 10(operand);
    That's why macros typically use all uppercase letters for their names. Repeat that explanation for everywhere the macros are defined and you shouldn't have trouble finding your errors.

  3. #3
    Registered User
    Join Date
    May 2004
    Posts
    6
    thanks for the help. I have changed all te define in the Instruction header file, after the compilation, the new error messages come up like this:

    snow:Cproject$ gcc processor.c
    /usr/lib/gcc-lib/i386-redhat-linux/3.2.2/../../../crt1.o(.text+0x18): In function `_start':
    ../sysdeps/i386/elf/start.S:77: undefined reference to `main'
    /tmp/ccko1gwi.o(.text+0x47): In function `execute':
    : undefined reference to `readMemory'
    /tmp/ccko1gwi.o(.text+0xe6): In function `execute':
    : undefined reference to `load'
    /tmp/ccko1gwi.o(.text+0xf9): In function `execute':
    : undefined reference to `store'
    /tmp/ccko1gwi.o(.text+0x10c): In function `execute':
    : undefined reference to `add'
    /tmp/ccko1gwi.o(.text+0x11f): In function `execute':
    : undefined reference to `substract'
    /tmp/ccko1gwi.o(.text+0x132): In function `execute':
    : undefined reference to `divide'
    /tmp/ccko1gwi.o(.text+0x145): In function `execute':
    : undefined reference to `multiply'
    /tmp/ccko1gwi.o(.text+0x158): In function `execute':
    : undefined reference to `branch'
    /tmp/ccko1gwi.o(.text+0x16b): In function `execute':
    : undefined reference to `branchNeg'
    /tmp/ccko1gwi.o(.text+0x17e): In function `execute':
    : undefined reference to `branchZero'
    /tmp/ccko1gwi.o(.text+0x18b): In function `execute':
    : undefined reference to `halt'
    collect2: ld returned 1 exit status

    The "readMemory" function is declared in the "memory.h" header file which has been included in the "processor.c" file. The "memroy.h" file is like this:

    #define size 100
    int memory[size];
    int readMemory(int);
    void writeMemory(int, int);


    For the rest of the functions are all declared in the "Instructions.h" header file which is also included in the "processor.c". The header file is like this now:

    #define READ 10
    #define WRITE 11
    #define LOAD 20
    #define STORE 21
    #define ADD 30
    #define SUBSTRUCT 31
    #define DIVIDE 32
    #define MULTIPLY 33
    #define BRANCH 40
    #define BRANCHNEG 41
    #define BRANCHZERO 42
    #define HALT 43

    void read(int);
    void write(int);
    void load(int);
    void store(int);
    void add(int);
    void substract(int);
    void divide(int);
    void multiply(int);
    void branch(int);
    void branchNeg(int);
    void branchZero(int);
    void halt(void);

    The "processor.c" file is like this now:

    #include <stdio.h>
    //#include "Instructions.c"
    #include "memory.h"
    #include "processor.h"
    #include "Instructions.h"

    void execute(void)
    {
    int instructionRegister = 0;
    int instruction = 0;
    int operand = 0;
    accumulator = 0;
    instructionCounter = 0;
    while(instructionCounter<size)
    {
    instructionRegister = readMemory(instructionCounter);
    ++instructionCounter;
    instruction = instructionRegister/100;
    operand = instructionRegister%100;
    switch(instruction)
    {
    case READ: read(operand);
    break;
    case WRITE: write(operand);
    break;
    case LOAD: load(operand);
    break;
    case STORE: store(operand);
    break;
    case ADD: add(operand);
    break;
    case SUBSTRUCT: substract(operand);
    break;
    case DIVIDE: divide(operand);
    break;
    case MULTIPLY: multiply(operand);
    break;
    case BRANCH: branch(operand);
    break;
    case BRANCHNEG: branchNeg(operand);
    break;
    case BRANCHZERO: branchZero(operand);
    break;
    case HALT: halt();
    break;
    }
    }
    }

    Can you see why the compiler still can't recognise the functions????

  4. #4
    Registered User
    Join Date
    May 2004
    Posts
    127
    Have you actually written these functions or just prototyped them?

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,532
    Read the "read this first" posts
    Especially the one about posting code and using code tags
    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. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 09:15 PM
  3. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  4. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 09:33 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 12:10 AM

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