-4

Can somebody explain me why do I have this error and how should complex array initialization done in my case ?

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 #
7
  • What is t_cat_deptype_t ? Commented Apr 9, 2014 at 11:56
  • @MichaelWalz I have described it in the question, please reread Commented Apr 9, 2014 at 13:43
  • No you haven't described it, it's defined in table_defs/t_cat_deptype.h and I can't guess what is in that file. Commented Apr 9, 2014 at 13:46
  • @MichaelWalz , no I did describe it. Read the question again. Commented Apr 9, 2014 at 17:22
  • Your question is on hold. You should ask yourself why. Commented Apr 9, 2014 at 18:27

1 Answer 1

3

On the line

{"Pregunta",'\0'}.

in

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'}
        }
};

There is a . instead of a , at the end of the line. Which is also what the compiler tells you:

company.c:27:20: error: expected '}' before '.' token
Sign up to request clarification or add additional context in comments.

8 Comments

this is not the cause of the error, change the '.' by ',' and you will see. Also the compiler generates error from line 17, not 27.
The compiler tells you it starts from line 17, where you start initializing the array. If you look closer though, it goes all the way through until the line where the error is encountered. Which was the line that I showed you.
@TheMe90 the typo you pointed, has no relation to the compiler errors, if you remove it the same error appears. You just answered to get points, but to help me with the problem, downvote for that.
No, that's not true, and it's not worth it to fight over it. I just tried to explain what the compiler tells you, and if what you say is true, then there has to be something else wrong. I understand.
I'll give you this final piece of help: after you replaced the . with , and you recompile, you get a different error: error: extra brace group at end of initializer. Which is a different error.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.