复杂数组初始化

时间:2014-04-09 11:51:43

标签: c linux

有人可以解释一下我为什么会出现这个错误以及如何在我的情况下完成复杂的数组初始化?

z3 src # head -37 company.c
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include "company.h"
#include "mytypes.h"
#include "depserv.h"
#include "table_defs/t_cat_deptype.h"

#define NUM_DEFAULT_DEPTYPES            9
typedef struct itl_cat_deptypes_t {
        t_cat_deptype_t         deptypes[NUM_DEFAULT_DEPTYPES];
} itl_cat_deptypes_t;

itl_cat_deptypes_t cat_deptypes[2] = {
        {
                {"Information Request",'\0'},
                {"Question",'\0'},
                {"Meeting",'\0'},
                {"Event",'\0'},
                {"Task",'\0'},
                {"Objective/Goal",'\0'},
                {"Authorization Request",'\0'},
                {"Dependency",'\0'},
                {"Custom",'\0'}
        },{
                {"Solicitud de Informacion",'\0'},
                {"Pregunta",'\0'},
                {"Junta",'\0'},
                {"Evento",'\0'},
                {"Tarea",'\0'},
                {"Objetivo/Meta",'\0'},
                {"Solicitud de Autorizacion",'\0'},
                {"Dependencia",'\0'},
                {"Personalizado",'\0'}
        }
};

z3 src # head table_defs/t_cat_deptype.h
#ifndef _T_CAT_DEPTYPE_
#define _T_CAT_DEPTYPE_

typedef struct t_cat_deptype_t {
        char                            description[64];
        char                            inactive;
} t_cat_deptype_t;

#endif

z3 src # make company.o
gcc -ggdb -Wmissing-prototypes -Wmissing-declarations -Wunused -Winline -Wno-format      -Wstrict-prototypes -Wimplicit-function-declaration -fmax-errors=5 -D_GNU_SOURCE -I./table_defs  -c company.c
cc1: warning: command line option "-fmax-errors=5" is valid for Fortran but not for C
company.c:17:3: error: extra brace group at end of initializer
company.c:17:3: error: (near initialization for 'cat_deptypes[0]')
company.c:17:3: warning: excess elements in struct initializer
company.c:17:3: warning: (near initialization for 'cat_deptypes[0]')
company.c:18:3: error: extra brace group at end of initializer
company.c:18:3: error: (near initialization for 'cat_deptypes[0]')
company.c:18:3: warning: excess elements in struct initializer
company.c:18:3: warning: (near initialization for 'cat_deptypes[0]')
company.c:19:3: error: extra brace group at end of initializer
company.c:19:3: error: (near initialization for 'cat_deptypes[0]')
company.c:19:3: warning: excess elements in struct initializer
company.c:19:3: warning: (near initialization for 'cat_deptypes[0]')
company.c:20:3: error: extra brace group at end of initializer
company.c:20:3: error: (near initialization for 'cat_deptypes[0]')
company.c:20:3: warning: excess elements in struct initializer
company.c:20:3: warning: (near initialization for 'cat_deptypes[0]')
company.c:21:3: error: extra brace group at end of initializer
company.c:21:3: error: (near initialization for 'cat_deptypes[0]')
company.c:21:3: warning: excess elements in struct initializer
company.c:21:3: warning: (near initialization for 'cat_deptypes[0]')
company.c:22:3: error: extra brace group at end of initializer
company.c:22:3: error: (near initialization for 'cat_deptypes[0]')
company.c:22:3: warning: excess elements in struct initializer
company.c:22:3: warning: (near initialization for 'cat_deptypes[0]')
company.c:23:3: error: extra brace group at end of initializer
company.c:23:3: error: (near initialization for 'cat_deptypes[0]')
company.c:23:3: warning: excess elements in struct initializer
company.c:23:3: warning: (near initialization for 'cat_deptypes[0]')
company.c:24:3: error: extra brace group at end of initializer
company.c:24:3: error: (near initialization for 'cat_deptypes[0]')
company.c:24:3: warning: excess elements in struct initializer
company.c:24:3: warning: (near initialization for 'cat_deptypes[0]')
company.c:27:3: error: extra brace group at end of initializer
company.c:27:3: error: (near initialization for 'cat_deptypes[1]')
company.c:27:3: warning: excess elements in struct initializer
company.c:27:3: warning: (near initialization for 'cat_deptypes[1]')
company.c:27:20: error: expected '}' before '.' token
make: *** [company.o] Error 1
z3 src #

1 个答案:

答案 0 :(得分:3)

在线

{"Pregunta",'\0'}.

itl_cat_deptypes_t cat_deptypes[2] = {
        {
                {"Information Request",'\0'},
                {"Question",'\0'},
                {"Meeting",'\0'},
                {"Event",'\0'},
                {"Task",'\0'},
                {"Objective/Goal",'\0'},
                {"Authorization Request",'\0'},
                {"Dependency",'\0'},
                {"Custom",'\0'}
        },{
                {"Solicitud de Informacion",'\0'},
                {"Pregunta",'\0'}.
                {"Junta",'\0'},
                {"Evento",'\0'},
                {"Tarea",'\0'},
                {"Objetivo/Meta",'\0'},
                {"Solicitud de Autorizacion",'\0'},
                {"Dependencia",'\0'},
                {"Personalizado",'\0'}
        }
};

行尾有.而不是,。这也是编译器告诉你的内容:

company.c:27:20: error: expected '}' before '.' token