This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

managing multiple files

Hi,

I'm using Silabs IDE and KEIL C51.

I need to modify the PUTCHAR.C and to add it in my project. The problem is, in my MAIN.C file I have declared a circular ring buffer (I'm using the buffer for UART transmit) wich is delared:

xdata RingBuf rbTX0; // Transmit buffer

But in the PUTCHAR.C I'm writing to this buffer. The problem is when I compile I get an error POINTER TO DIFFERENT OBJECT.

I have added the putchar.c to my project.

So how can I use a variable in a file that was declared in an other file ?

Thanks,

Aldrin,

Parents
  • So how can I use a variable in a file that was declared in an other file ?

    Header (.h) files are used to describe the interface to a module. Data items should be declared with the extern keyword. This header file would then be #include'd in any .c file that wishes to access that data.

    The item must also be defined -- that is, have storage allocated for it. There should be only one definition for an item. So, definitions (storage allocations) do not belong in the header files, but in .c files.

    RingBuffer.h:
    // let the world know that somewhere there exists a RingBuf called rbTX0
    extern xdata RingBuf rbTX0;

    RingBuffer.c:
    // here's where the RingBuf rbTX0 actually lives
    xdata RingBuf rbTX0;

    putchar.c:
    // I'd like to have access to the RingBuf rbTX0
    #include "RingBuffer.h"

Reply
  • So how can I use a variable in a file that was declared in an other file ?

    Header (.h) files are used to describe the interface to a module. Data items should be declared with the extern keyword. This header file would then be #include'd in any .c file that wishes to access that data.

    The item must also be defined -- that is, have storage allocated for it. There should be only one definition for an item. So, definitions (storage allocations) do not belong in the header files, but in .c files.

    RingBuffer.h:
    // let the world know that somewhere there exists a RingBuf called rbTX0
    extern xdata RingBuf rbTX0;

    RingBuffer.c:
    // here's where the RingBuf rbTX0 actually lives
    xdata RingBuf rbTX0;

    putchar.c:
    // I'd like to have access to the RingBuf rbTX0
    #include "RingBuffer.h"

Children