Menu

#2 problems with arraysize of a typedef

open
nobody
None
5
2003-02-21
2003-02-21
Anonymous
No

Defining an array with a self defined compound type
gives a wrong error.
example:

typedef struct STRUCT_Table
{
char c1;
char c2;

} T_Table;

T_Table table[3]=
{
1,2,3,4,5,6

};

with the splint switch:
splint -weak -nestcomment -type -retvalother

brings the error
test.c(11,3): Initializer block for table has 6 elements,
but declared as
T_Table [3]: 1, 2, 3, 4, 5, 6
Initializer block contains more elements than the size
of a declared array.
(Use -initsize to inhibit warning)

The compiler thinks the code is ok. I also.

Discussion

  • David Larochell

    David Larochell - 2003-03-05

    Logged In: YES
    user_id=61835

    I don't have the C standard in front of me so I'm not sure
    of the exact semantics of array initialization.

    T_Table table[3]=
    {
    {1,2},{3,4}, {5,6}

    };
    Should have the same effect, but will not produce a Splint
    warning.

     
  • David Larochell

    David Larochell - 2003-03-07

    Logged In: YES
    user_id=61835

    This message was posted anonymously and it's been a while
    since it was orginally posted so I'm goingg to close it out.

    I'm also recategorizing it as the support request.

    If the person who posted this has additionally questions they
    can reopen the message or send us email at "splint at splint
    dot org"

    Thanks for using Splint

     

Log in to post a comment.