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

How to use extern sbit declare?

I declare a variable unsigned char bdata Kde in a.c.

[in file a.c]

unsigned char bdata Kde;

Than I want to use the variable inb.c.
[in file b.c]
#include <stdio.h>
.....
extern unsigned char bdata Kde;
sbit testbit=Kde^1;
void main(void)
{......}

:error C141:.......a.c:syntax error near 'sbit'

why?

Parents
  • I think that the root of the problem is that the linker cannot be left to work out bit addresses - only the compiler can do that. I am not sure why that should be the case, but I guess that it has something to do with the linker dealing only with relative addressing with simple offsets.

    You will need to define testbit in file a.c and export the bit address from there. So, you will have:

    [in file a.c]

    bdata unsigned char Kde;
    sbit testbit=Kde^1;
    
    [in file b.c]
    #include <stdio.h>
    .....
    extern bdata unsigned char Kde;
    extern testbit; 
    
    void main(void)
    {......}
    
    Placing of bdata keyword is just my personal preference. I have not actually tried this, but I think it should work! Good luck.

Reply
  • I think that the root of the problem is that the linker cannot be left to work out bit addresses - only the compiler can do that. I am not sure why that should be the case, but I guess that it has something to do with the linker dealing only with relative addressing with simple offsets.

    You will need to define testbit in file a.c and export the bit address from there. So, you will have:

    [in file a.c]

    bdata unsigned char Kde;
    sbit testbit=Kde^1;
    
    [in file b.c]
    #include <stdio.h>
    .....
    extern bdata unsigned char Kde;
    extern testbit; 
    
    void main(void)
    {......}
    
    Placing of bdata keyword is just my personal preference. I have not actually tried this, but I think it should work! Good luck.

Children
No data