This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

gcc 2.95.2 - error in static init of tables


Is it a bug  or a regression???
 
 

There is a problem during the static table (stucture table ) initialisation like this one :
                                                    typedef struct _MyStructure {
                                                    int a : 8;
                                                    int b : 8;
                                                    int : 0; /* <= problem with gcc version 2.95.2 */
                                                    int val;
                                                    } MyStructure;
                                                    All fields declared after the line "int : 0;" are initialisated to 0 !!
                                                    The line "int : 0;" is an  field alignment directive (see the Kernighan & Ritchie) and not a  "reset" !
                                                    Is it a regress !
                                                    Example to have the problem :
 

                                                    #include <stdio.h>
                                                    typedef struct _MyStructure {
                                                    int a : 8;
                                                    int b : 8;
                                                    int : 0; /* <= problem with gcc version 2.95.2 */
                                                    int val;
                                                    } MyStructure;
                                                    typedef struct _MyStructure2 {
                                                    int a : 8;
                                                    int b : 8;
                                                    int val;
                                                    } MyStructure2;
                                                    typedef struct _MyStructure3 {
                                                    int : 0;
                                                    int a : 8;
                                                    int b : 8;
                                                    int val;
                                                    } MyStructure3;
                                                    #define TABSIZE 2
                                                    #define VAL0 234
                                                    #define VAL1 643
                                                    MyStructure tab[TABSIZE] = {
                                                    {
                                                    2, 3, VAL0
                                                    },
                                                    {
                                                    5, 33, VAL1
                                                    }
                                                    };
                                                    MyStructure2 tab2[TABSIZE] = {
                                                    {
                                                    2, 3, VAL0
                                                    },
                                                    {
                                                    5, 33, VAL1
                                                    }
                                                    };
                                                    MyStructure3 tab3[TABSIZE] = {
                                                    {
                                                    2, 3, VAL0
                                                    },
                                                    {
                                                    5, 33, VAL1
                                                    }
                                                    };
                                                    int val[2] = { VAL0, VAL1 };
                                                    int
                                                    main()
                                                    {
                                                    int i = 0;
                                                    for(i = 0; i < TABSIZE; i++) {
                                                    if(tab[i].val != val[i]) {
                                                    printf("Unexpected val for tab[%d].val : %d instead of %d\n", i, tab[i].val, val[i]);
                                                    }
                                                    }
                                                    for(i = 0; i < TABSIZE; i++) {
                                                    if(tab2[i].val != val[i]) {
                                                    printf("Unexpected val for tab2[%d].val : %d instead of %d\n", i, tab[i].val, val[i]);
                                                    }
                                                    }
                                                    for(i = 0; i < TABSIZE; i++) {
                                                    if(tab3[i].val != val[i]) {
                                                    printf("Unexpected val for tab3[%d].val : %d instead of %d\n", i, tab[i].val, val[i]);
                                                    }
                                                    }

                                                    return 0;
                                                    }

-- 
+-----------------------------------------------------------------+
| Eric HEBERT                                                     |
|                                                    META SYSTEMS |
|                                                       LP 853    |
|                                                  Batiment SIGMA |
| Tel: 33-(0)1.64.86.61.00                       3, Ave du Canada |
| Fax: 33-(0)1.64.86.61.61                91075 COURTABOEUF CEDEX |
|                                                                 |
| E-mail: eric_hebert@mentor.com                                  |
+-----------------------------------------------------------------+
 
Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]