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

Compiler error 143

Can anyone tell me why this piece of code builds with error 143, and how to get it to build without errors?

typedef unsigned char U8;
typedef unsigned long int U32;

#define B0(x) ((U8) ((U32)x&0xFF))
#define B1(x) ((U8)(((U32)x&0xFF00)>>8))
#define B2(x) ((U8)(((U32)x&0xFF0000)>>16))
#define B3(x) ((U8)(((U32)x&0xFF000000)>>24))

void foo(void);

BYTE abc[]={
    B0(foo),
    B1(foo),
    B2(foo),
    B3(foo)
};

void foo(void){
}

Thanks... Dave.

Parents
  • Hm. It does sound like what I mentioned earlier, then. Since the compiler doesn't know the value of foo at compile time, it can't calculate (U32)foo >> 24 (for example) to be part of the initializer.

    Presumably you know which bytes are which in this array. If the data is structured, could you declare a struct for the data, and then initialize that struct? E.g.,

    typedef struct
       {
       U8 someByte;
       void (*f)(void);  // alignment restrictions on C166?
       U16 someCounter;
       } HeterogeneousData;
    
    HeterogeneousData abc =
       {
       0,
       foo,
       0xdead
       };
    

    If you later need to access that memory as an array of bytes, just cast: ((U8*)&abc).

    The other fallback I would suggest is to initialize the memory array at run time. That will likely cost you a few more bytes of code, though.

Reply
  • Hm. It does sound like what I mentioned earlier, then. Since the compiler doesn't know the value of foo at compile time, it can't calculate (U32)foo >> 24 (for example) to be part of the initializer.

    Presumably you know which bytes are which in this array. If the data is structured, could you declare a struct for the data, and then initialize that struct? E.g.,

    typedef struct
       {
       U8 someByte;
       void (*f)(void);  // alignment restrictions on C166?
       U16 someCounter;
       } HeterogeneousData;
    
    HeterogeneousData abc =
       {
       0,
       foo,
       0xdead
       };
    

    If you later need to access that memory as an array of bytes, just cast: ((U8*)&abc).

    The other fallback I would suggest is to initialize the memory array at run time. That will likely cost you a few more bytes of code, though.

Children
  • Thanks to all of you who participated in my enlightenment, especially those who provided the technical answer (hence, understanding) I was looking for. Thankfully there are many different ways I can attempt to solve the related problem, and I'm on my merry way towards an alternative solution.