Skip to content

Commit 46fb5a8

Browse files
committed
pure C: fix Warnings
gcc provides good tips on pure C functions, let's ack't them. pure: functions that are idempotent since they do not rely on internal states. They are like some "const", weaker. They do not have side effects. use case: x = le16(p); y = le16(p); could be optimized to: x = le16(p); # le16 is pure y = x;
1 parent b45d1ed commit 46fb5a8

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/pmbus_io.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ pmbus_lin16u_to_double(uint16_t raw, int exp5) {
111111
}
112112

113113
uint16_t
114-
le16(const uint8_t *p) {
114+
BMR_PURE le16(const uint8_t *p) {
115115
return (uint16_t)(
116116
(uint16_t)p[0]
117117
| ((uint16_t)p[1] << 8)
@@ -120,7 +120,7 @@ le16(const uint8_t *p) {
120120
}
121121

122122
uint32_t
123-
le32(const uint8_t *p) {
123+
BMR_PURE le32(const uint8_t *p) {
124124
return (uint32_t) p[0]
125125
| ((uint32_t) p[1] << 8)
126126
| ((uint32_t) p[2] << 16)

src/pmbus_io.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77

88
#define D(xf) (double)((xf))
99

10+
#if defined(__GNUC__) || defined(__clang__)
11+
# define BMR_PURE __attribute__((pure))
12+
#else
13+
# define BMR_PURE
14+
#endif
15+
1016
/* TODO: align with PMBus-Specification-Rev-1-3-1-Part-II-20150313.pdf */
1117
/*
1218
* PMBus standard (generic):

0 commit comments

Comments
 (0)