Skip to content

Commit 0747e58

Browse files
dwmw2gizmocuz
authored andcommitted
MochadTCP/P1MeterBase: fix C++ One Definition Rule violations (#2408)
Fix the following build warnings seen with GCC 8. Untested as I have neither hardware, but Obviously Correct™. hardware/MochadTCP.cpp:20:3: warning: type ‘MatchType’ violates the C++ One Definition Rule [-Wodr] } MatchType; ^ hardware/P1MeterBase.cpp:19:3: note: an enum with different value name is defined in another translation unit } MatchType; ^ hardware/MochadTCP.cpp:29:16: warning: type ‘struct _tMatch’ violates the C++ One Definition Rule [-Wodr] typedef struct _tMatch { ^ hardware/P1MeterBase.cpp:59:16: note: a different type is defined in another translation unit typedef struct _tMatch { ^ hardware/MochadTCP.cpp:30:12: note: the first difference of corresponding definitions is field ‘matchtype’ MatchType matchtype; ^ hardware/P1MeterBase.cpp:60:12: note: a field of same name but different type is defined in another translation unit MatchType matchtype; ^ hardware/MochadTCP.cpp:20:3: note: type ‘MatchType’ itself violates the C++ One Definition Rule } MatchType; ^ hardware/P1MeterBase.cpp:19:3: note: the incompatible type is defined here } MatchType; ^
1 parent 5a04aae commit 0747e58

File tree

2 files changed

+22
-22
lines changed

2 files changed

+22
-22
lines changed

hardware/MochadTCP.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,30 @@
1111

1212
#define RETRY_DELAY 30
1313

14-
typedef enum {
14+
enum _eMochadMatchType {
1515
ID=0,
1616
STD,
1717
LINE17,
1818
LINE18,
1919
EXCLMARK
20-
} MatchType;
20+
};
2121

22-
typedef enum {
22+
enum _eMochadType {
2323
MOCHAD_STATUS=0,
2424
MOCHAD_UNIT,
2525
MOCHAD_ACTION,
2626
MOCHAD_RFSEC
27-
} MochadType;
27+
};
2828

29-
typedef struct _tMatch {
30-
MatchType matchtype;
31-
MochadType type;
29+
typedef struct {
30+
_eMochadMatchType matchtype;
31+
_eMochadType type;
3232
const char* key;
3333
int start;
3434
int width;
35-
} Match;
35+
} MochadMatch;
3636

37-
static Match matchlist[] = {
37+
static MochadMatch matchlist[] = {
3838
{STD, MOCHAD_STATUS, "House ", 6, 255},
3939
{STD, MOCHAD_UNIT, "Tx PL HouseUnit: ", 17, 9},
4040
{STD, MOCHAD_UNIT, "Rx PL HouseUnit: ", 17, 9},
@@ -239,13 +239,13 @@ void MochadTCP::MatchLine()
239239
uint8_t i;
240240
int j,k;
241241
uint8_t found=0;
242-
Match t;
242+
MochadMatch t;
243243
char value[20]="";
244244
std::string vString;
245245

246246

247247

248-
for(i=0;(i<sizeof(matchlist)/sizeof(Match))&(!found);i++)
248+
for(i=0;(i<sizeof(matchlist)/sizeof(MochadMatch))&(!found);i++)
249249
{
250250
t = matchlist[i];
251251
switch(t.matchtype)

hardware/P1MeterBase.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
#define CRC16_ARC 0x8005
99
#define CRC16_ARC_REFL 0xA001
1010

11-
typedef enum {
11+
enum _eP1MatchType {
1212
ID=0,
1313
EXCLMARK,
1414
STD,
1515
DEVTYPE,
1616
GAS,
1717
LINE17,
1818
LINE18
19-
} MatchType;
19+
};
2020

2121
#define P1SMID "/" // Smart Meter ID. Used to detect start of telegram.
2222
#define P1VER "1-3:0.2.8" // P1 version
@@ -37,7 +37,7 @@ typedef enum {
3737
#define P1MBTYPE "0-n:24.1.0" // M-Bus device type
3838
#define P1EOT "!" // End of telegram.
3939

40-
typedef enum {
40+
enum _eP1Type {
4141
P1TYPE_SMID=0,
4242
P1TYPE_END,
4343
P1TYPE_VERSION,
@@ -54,18 +54,18 @@ typedef enum {
5454
P1TYPE_GASUSAGEDSMR4,
5555
P1TYPE_GASTIMESTAMP,
5656
P1TYPE_GASUSAGE
57-
} P1Type;
57+
};
5858

59-
typedef struct _tMatch {
60-
MatchType matchtype;
61-
P1Type type;
59+
typedef struct {
60+
_eP1MatchType matchtype;
61+
_eP1Type type;
6262
const char* key;
6363
const char* topic;
6464
int start;
6565
int width;
66-
} Match;
66+
} P1Match;
6767

68-
Match matchlist[] = {
68+
P1Match matchlist[] = {
6969
{ID, P1TYPE_SMID, P1SMID, "", 0, 0},
7070
{EXCLMARK, P1TYPE_END, P1EOT, "", 0, 0},
7171
{STD, P1TYPE_VERSION, P1VER, "version", 10, 2},
@@ -154,11 +154,11 @@ bool P1MeterBase::MatchLine()
154154
return true; //null value (startup)
155155
uint8_t i;
156156
uint8_t found=0;
157-
Match *t;
157+
P1Match *t;
158158
char value[20]="";
159159
std::string vString;
160160

161-
for(i=0;(i<sizeof(matchlist)/sizeof(Match))&(!found);i++)
161+
for(i=0;(i<sizeof(matchlist)/sizeof(P1Match))&(!found);i++)
162162
{
163163
t = &matchlist[i];
164164
switch(t->matchtype)

0 commit comments

Comments
 (0)