Duplicate Case Value Error C
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business duplicate case value previously used here Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs arduino duplicate case value Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just
"duplicate Case Label"
like you, helping each other. Join them; it only takes a minute: Sign up switch statement duplicate error up vote -1 down vote favorite #include
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Macro to avoid duplicate case value up vote 2 down vote favorite I am http://stackoverflow.com/questions/22041092/switch-statement-duplicate-error using a switch expression in C in order to evaluate the errno variable. According to the man page for send(): EAGAIN or EWOULDBLOCK The socket is marked nonblocking and the requested operation would block. POSIX.1-2001 allows either error to be returned for this case,and does not require these constants to have the same value, so a portable application should check for both possibilities. Since my application must be portable, I http://stackoverflow.com/questions/27509061/macro-to-avoid-duplicate-case-value have to do: switch (errno): case EWOULDBLOCK: case EAGAIN: //do whatever break; case EINTR: //... The problem is that for some platforms, EWOULDBLOCK and EAGAIN do have the same value, so when compiling I get: connection.cxx:190:5: error: duplicate case value case EWOULDBLOCK: ^ connection.cxx:189:5: error: previously used here case EAGAIN: ^ So I thought I could use a macro macro that depending on whether EWOULDBLOCK and EAGAIN have the same value or not for the platform adds that line to the code or omits it. Any idea on how to write that macro? c macros share|improve this question asked Dec 16 '14 at 16:14 user2891462 475518 add a comment| 2 Answers 2 active oldest votes up vote 8 down vote accepted Something like: #if EAGAIN != EWOULDBLOCK case EAGAIN: #endif case EWOULDBLOCK: edit: however if you're going to have many switch switch statements, a macro would be better than the conditional compilation. Something like: #if EAGAIN == EWOULDBLOCK #define MY_AGAIN EAGAIN #else #define MYAGAIN EAGAIN: case EWOULDBLOCK #endif Then to use it: case MY_AGAIN: You'll see that the colon is not part of the macro at the point where it is called: case ---->MACRO GOES HERE<-----: however in the second case, when expanded in the context of the or
but I'm getting an error. Here's the code. http://www.cplusplus.com/forum/beginner/101401/ 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include