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

Syntax error on struct variable initialization

I get syntax error for valid C-syntax. It seems like the compiler thinks that the initializer of the variable must come from a constant expression whereas a variable assignment should be accepted as well.

A workaround is to make the declaration separate from the initialization.

Same problem in both C51 and CX51.

foo_t f = {1, 2};
foo_t A[10] = { { 1, 2 } };

void foo(int i, foo_t* foo_p)
{
    foo_t x = f;    // C51: error C248: aggregate initialization needs curly braces
    foo_t y = A[i]; // C51: error C248: aggregate initialization needs curly braces
    foo_t z = foo_p[i]; // C51: non-address/-constant initializer
    foo_t w; w = foo_p[i]; // OK
}

Parents
  • Adding the version numbers to my previous post.

    Tool Version Numbers:
    Toolchain: PK51 Prof. Developers Kit Version: 8.18
    Toolchain Path: C:\Keil\C51\BIN\
    C Compiler: C51.Exe V8.18
    Assembler: A51.Exe V8.01
    Linker/Locator: BL51.Exe V6.20
    Librarian: LIB51.Exe V4.24
    Hex Converter: OH51.Exe V2.6
    CPU DLL: S8051.DLL V3.65
    Dialog DLL: DP51.DLL V2.54

Reply
  • Adding the version numbers to my previous post.

    Tool Version Numbers:
    Toolchain: PK51 Prof. Developers Kit Version: 8.18
    Toolchain Path: C:\Keil\C51\BIN\
    C Compiler: C51.Exe V8.18
    Assembler: A51.Exe V8.01
    Linker/Locator: BL51.Exe V6.20
    Librarian: LIB51.Exe V4.24
    Hex Converter: OH51.Exe V2.6
    CPU DLL: S8051.DLL V3.65
    Dialog DLL: DP51.DLL V2.54

Children
No data