Menu

#998 Initialization of structure array

closed-invalid
nobody
5
2013-05-25
2005-10-22
Anonymous
No

email: jim@jimcramer.net

Example below similar to Kernihan & Ritchie [1978], p 124.
Gives error 69 using SDCC.

struct {
int a;
int b;
} astruc[] = {
1, 1,
2, 2
};

void main(void)
{
}

Discussion

  • Raphael Neider

    Raphael Neider - 2005-10-22
    • labels: --> C-Front End
    • milestone: --> non_bugs
    • status: open --> pending-invalid
     
  • Raphael Neider

    Raphael Neider - 2005-10-22

    Logged In: YES
    user_id=1115835

    SDCC output:
    init.c:4: error 69: struct/union/array 'astruc'
    :initialization needs curly braces

    This is perfectly fine for me -- add curly braces around
    each struct initializer and you are done.
    I guess your code is non-valid ANSI C code (according do a
    draft of the standard, struct and union initializers must be
    brace-enclosed (6.7.8:16)).

    Can anyone confirm this?

    Fixed code:
    struct {
    int a;
    int b;
    } astruc[] = {
    {1, 1},
    {2, 2}
    };

    void main(void)
    {
    }

     
  • Nobody/Anonymous

    Logged In: NO

    I've always kept my old copy of K&R as my C reference
    standard. However, if it compiles (confirmed) with extra
    braces (whether standard or not) I'm happy. Thanks for the
    quick turn-around.
    Jim Cramer

     
  • Maarten Brock

    Maarten Brock - 2005-10-23

    Logged In: YES
    user_id=888171

    Jim,

    Allthough I don't have my copy of C99 at hand right now, I
    know SDCC does not support initialization without the extra
    braces. Using them however makes so much clearer code
    and it definitely is according to the standard.

    And there are more things in K&R that SDCC does not
    support, like:
    foo()
    int a;
    {...}
    to declare parameter a.

    I don't think we have any intention on changing that.
    Greets,
    Maarten

     
  • Maarten Brock

    Maarten Brock - 2005-10-23
    • status: pending-invalid --> closed-invalid
     

Log in to post a comment.