Skip to content

Commit 4fcaba2

Browse files
alwa-nordiccarlescufi
authored andcommitted
Bluetooth: Host: Fix GCC 7 error: non-constant expr in initializer
Using a const-qualified object in a static initializer is implementation specific in C, and it does not work in GCC 7. Before this change, `write_appearance` was a pointer object if CONFIG_BT_DEVICE_APPEARANCE_GATT_WRITABLE was disabled. This change removes that object in favor of a macro `GAP_APPEARANCE_WRITE_HANDLER`. Signed-off-by: Aleksander Wasaznik <[email protected]>
1 parent 21a6456 commit 4fcaba2

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

subsys/bluetooth/host/gatt.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ static ssize_t read_appearance(struct bt_conn *conn,
130130
}
131131

132132
#if defined(CONFIG_BT_DEVICE_APPEARANCE_GATT_WRITABLE)
133-
134133
static ssize_t write_appearance(struct bt_conn *conn, const struct bt_gatt_attr *attr,
135134
const void *buf, uint16_t len, uint16_t offset,
136135
uint8_t flags)
@@ -159,19 +158,16 @@ static ssize_t write_appearance(struct bt_conn *conn, const struct bt_gatt_attr
159158

160159
return len;
161160
}
162-
163-
#else /* CONFIG_BT_DEVICE_APPEARANCE_GATT_WRITABLE */
164-
static ssize_t (* const write_appearance)(struct bt_conn *conn,
165-
const struct bt_gatt_attr *attr, const void *buf, uint16_t len,
166-
uint16_t offset, uint8_t flags) = NULL;
167161
#endif /* CONFIG_BT_DEVICE_APPEARANCE_GATT_WRITABLE */
168162

169163
#if CONFIG_BT_DEVICE_APPEARANCE_GATT_WRITABLE
170164
#define GAP_APPEARANCE_PROPS (BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE)
171165
#define GAP_APPEARANCE_PERMS (BT_GATT_PERM_READ | BT_GATT_PERM_WRITE_AUTHEN)
166+
#define GAP_APPEARANCE_WRITE_HANDLER write_appearance
172167
#else
173168
#define GAP_APPEARANCE_PROPS BT_GATT_CHRC_READ
174169
#define GAP_APPEARANCE_PERMS BT_GATT_PERM_READ
170+
#define GAP_APPEARANCE_WRITE_HANDLER NULL
175171
#endif
176172

177173
#if defined (CONFIG_BT_GAP_PERIPHERAL_PREF_PARAMS)
@@ -241,7 +237,8 @@ BT_GATT_SERVICE_DEFINE(_2_gap_svc,
241237
BT_GATT_PERM_READ, read_name, NULL, NULL),
242238
#endif /* CONFIG_BT_DEVICE_NAME_GATT_WRITABLE */
243239
BT_GATT_CHARACTERISTIC(BT_UUID_GAP_APPEARANCE, GAP_APPEARANCE_PROPS,
244-
GAP_APPEARANCE_PERMS, read_appearance, write_appearance, NULL),
240+
GAP_APPEARANCE_PERMS, read_appearance,
241+
GAP_APPEARANCE_WRITE_HANDLER, NULL),
245242
#if defined(CONFIG_BT_CENTRAL) && defined(CONFIG_BT_PRIVACY)
246243
BT_GATT_CHARACTERISTIC(BT_UUID_CENTRAL_ADDR_RES,
247244
BT_GATT_CHRC_READ, BT_GATT_PERM_READ,

0 commit comments

Comments
 (0)