E
Esash
Hello all,
I am trying to compile this code with gcc. I wrote this sample code to test this pattern so that I can incorporate the same pattern in my project. But I am not able to compile this code. Here is the code.
#include <stdio.h>
#define EK "1"
#define DO "2"
const char *num[] = { EK, DO };
typedef enum data_t_ {
ONE,
TWO,
} data_t;
typedef struct dat_t {
char *ptr;
int len;
} dat_t;
const dat_t *dat[] = {
{ num[ONE], sizeof(num[ONE]) },
{ num[TWO], sizeof(num[TWO]) },
};
int main()
{
int i;
for ( i = 0; i < 2; i++ ) {
printf("%s\t%d\n", dat->ptr, dat->len);
}
return 0;
}
I get the following errors :
index.c:19:2: warning: braces around scalar initializer [enabled by default]
index.c:19:2: warning: (near initialization for 'dat[0]') [enabled by default]
index.c:19:2: error: initializer element is not constant
index.c:19:2: error: (near initialization for 'dat[0]')
index.c:19:2: warning: excess elements in scalar initializer [enabled by default
]
index.c:19:2: warning: (near initialization for 'dat[0]') [enabled by default]
index.c:20:2: warning: braces around scalar initializer [enabled by default]
index.c:20:2: warning: (near initialization for 'dat[1]') [enabled by default]
index.c:20:2: error: initializer element is not constant
index.c:20:2: error: (near initialization for 'dat[1]')
index.c:20:2: warning: excess elements in scalar initializer [enabled by default
]
index.c:20:2: warning: (near initialization for 'dat[1]') [enabled by default]
Please help.
Thanks,
Esash
I am trying to compile this code with gcc. I wrote this sample code to test this pattern so that I can incorporate the same pattern in my project. But I am not able to compile this code. Here is the code.
#include <stdio.h>
#define EK "1"
#define DO "2"
const char *num[] = { EK, DO };
typedef enum data_t_ {
ONE,
TWO,
} data_t;
typedef struct dat_t {
char *ptr;
int len;
} dat_t;
const dat_t *dat[] = {
{ num[ONE], sizeof(num[ONE]) },
{ num[TWO], sizeof(num[TWO]) },
};
int main()
{
int i;
for ( i = 0; i < 2; i++ ) {
printf("%s\t%d\n", dat->ptr, dat->len);
}
return 0;
}
I get the following errors :
index.c:19:2: warning: braces around scalar initializer [enabled by default]
index.c:19:2: warning: (near initialization for 'dat[0]') [enabled by default]
index.c:19:2: error: initializer element is not constant
index.c:19:2: error: (near initialization for 'dat[0]')
index.c:19:2: warning: excess elements in scalar initializer [enabled by default
]
index.c:19:2: warning: (near initialization for 'dat[0]') [enabled by default]
index.c:20:2: warning: braces around scalar initializer [enabled by default]
index.c:20:2: warning: (near initialization for 'dat[1]') [enabled by default]
index.c:20:2: error: initializer element is not constant
index.c:20:2: error: (near initialization for 'dat[1]')
index.c:20:2: warning: excess elements in scalar initializer [enabled by default
]
index.c:20:2: warning: (near initialization for 'dat[1]') [enabled by default]
Please help.
Thanks,
Esash