G
Guest
I came over this code which puzzled me. Isn't the enum supposed to
have an identifier?
enum {
BT_CONNECTED = 1, /* Equal to TCP_ESTABLISHED to make net code happy */
BT_OPEN,
BT_BOUND,
BT_LISTEN,
BT_CONNECT,
BT_CONNECT2,
BT_CONFIG,
BT_DISCONN,
BT_CLOSED
};
Following this, I played around a bit, and came up with the program
below, which I had hoped would provoke the compiler into issuing a
warning about type mismatch (or something along those lines). Which
it didn't. (gcc -std=c99 -Wall -pedantic).
Care to comment?
With kind regards
Asbjørn Sæbø
#include <stdio.h>
typedef enum
{
M_A = 1,
M_B,
M_C,
M_D
} M_type;
typedef enum
{
N_A = 1,
N_B,
N_C,
N_D
} N_type;
void myfunc(M_type myvar)
{
printf("Inside myfunc, myvar is %d\n", myvar);
}
int main(void)
{
N_type a = N_B;
myfunc(a); /* Feed variable of N_type into function expecting M_type */
return 0;
}
have an identifier?
enum {
BT_CONNECTED = 1, /* Equal to TCP_ESTABLISHED to make net code happy */
BT_OPEN,
BT_BOUND,
BT_LISTEN,
BT_CONNECT,
BT_CONNECT2,
BT_CONFIG,
BT_DISCONN,
BT_CLOSED
};
Following this, I played around a bit, and came up with the program
below, which I had hoped would provoke the compiler into issuing a
warning about type mismatch (or something along those lines). Which
it didn't. (gcc -std=c99 -Wall -pedantic).
Care to comment?
With kind regards
Asbjørn Sæbø
#include <stdio.h>
typedef enum
{
M_A = 1,
M_B,
M_C,
M_D
} M_type;
typedef enum
{
N_A = 1,
N_B,
N_C,
N_D
} N_type;
void myfunc(M_type myvar)
{
printf("Inside myfunc, myvar is %d\n", myvar);
}
int main(void)
{
N_type a = N_B;
myfunc(a); /* Feed variable of N_type into function expecting M_type */
return 0;
}