[C con Clase] sintaxis incorrecta al declarar un tipo static struct

Steven Richard Davidson stevenrichard.davidson en gmail.com
Jue Jul 16 16:31:51 CEST 2009


Hola Susana,

On Thu, Jul 16, 2009 at 6:07 AM, Susana Sacie<susanitis en gmail.com> wrote:
> VC++ me da muchos errores de sintaxis al intentar hacer la siguiente
> declaración:
>
> struct dg_param {
>     int        group;
>     char         *name;
>     char        sfid;
>     u_int16_t    fid;
>     char        tag;
> };
>
> static struct dg_param dg_params[] = {
> {              .name =  "COM", .sfid = 0x1e, .fid = 0x011e, .tag = 0x60, },
> { .group =  1, .name =  "DG1", .sfid = 0x01, .fid = 0x0101, .tag = 0x61, },
> { .group =  2, .name =  "DG2", .sfid = 0x02, .fid = 0x0102, .tag = 0x75, },
> { .group =  3, .name =  "DG3", .sfid = 0x03, .fid = 0x0103, .tag = 0x63, },
> { .group =  4, .name =  "DG4", .sfid = 0x04, .fid = 0x0104, .tag = 0x76, },
> { .group =  5, .name =  "DG5", .sfid = 0x05, .fid = 0x0105, .tag = 0x65, },
> { .group =  6, .name =  "DG6", .sfid = 0x06, .fid = 0x0106, .tag = 0x66, },
> { .group =  7, .name =  "DG7", .sfid = 0x07, .fid = 0x0107, .tag = 0x67, },
> { .group =  8, .name =  "DG8", .sfid = 0x08, .fid = 0x0108, .tag = 0x68, },
> { .group =  9, .name =  "DG9", .sfid = 0x09, .fid = 0x0109, .tag = 0x69, },
> { .group = 10, .name = "DG10", .sfid = 0x0a, .fid = 0x010a, .tag = 0x6a, },
> { .group = 11, .name = "DG11", .sfid = 0x0b, .fid = 0x010b, .tag = 0x6b, },
> { .group = 12, .name = "DG12", .sfid = 0x0c, .fid = 0x010c, .tag = 0x6d, },
> { .group = 13, .name = "DG13", .sfid = 0x0d, .fid = 0x010d, .tag = 0x6e, },
> { .group = 14, .name = "DG14", .sfid = 0x0e, .fid = 0x010e, .tag = 0x6f, },
> { .group = 15, .name = "DG15", .sfid = 0x0f, .fid = 0x010f, .tag = 0x70, },
> { .group = 16, .name = "DG16", .sfid = 0x10, .fid = 0x0110, .tag = 0x75, },
> {              .name =  "SOD", .sfid = 0x1d, .fid = 0x011d, .tag = 0x77, },
> { 0 }
> };
>
> ¿por qué no me acepta esta estructura? , gracias.
>

No puedes indicar el nombre del miembro de la estructura en la
inicialización. Solamente puedes dar los valores. En tu caso,
simplemente escribe los valores en el orden de los miembros que
aparecen en la definición de la estructura. Esto es,

static struct dg_param dg_params[] = {
{ 0, "COM", 0x1e, 0x011e, 0x60, },
{ 1, "DG1", 0x01, 0x0101, 0x61, },
{ 2, "DG2", 0x02, 0x0102, 0x75, },
{ 3, "DG3", 0x03, 0x0103, 0x63, },
{ 4, "DG4", 0x04, 0x0104, 0x76, },
...
{ 0 }
};


Espero que esto te sirva.

Steven




Más información sobre la lista de distribución Cconclase