Eric Blake <ebl...@redhat.com> writes: > On 01/20/2016 11:08 AM, Markus Armbruster wrote: >> Eric Blake <ebl...@redhat.com> writes: >> >>> C compilers are allowed to represent enums as a smaller type >>> than int, if all enum values fit in the smaller type. There >>> are even compiler flags that force the use of this smaller >>> representation, and using them changes the ABI of a binary. >> >> Suggest "although using them". >> > > Okay. > > >>> with generated code changing as: >>> >>> | void visit_type_GuestDiskBusType(Visitor *v, GuestDiskBusType >>> | *obj, const char *name, Error **errp) >>> | { >>> |- visit_type_enum(v, (int *)obj, GuestDiskBusType_lookup, >>> "GuestDiskBusType", name, errp); >>> |+ int tmp = *obj; >>> |+ visit_type_enum(v, &tmp, GuestDiskBusType_lookup, "GuestDiskBusType", >>> name, errp); >>> |+ *obj = tmp; >>> | } >> >> Long lines. Do we have an example with a shorter enum name handy? > > Shortest is QType; runner-ups RxState and TpmType.
QType comes out okay: | void visit_type_QType(Visitor *v, QType *obj, const char *name, Error **errp) | { |- visit_type_enum(v, (int *)obj, QType_lookup, "QType", name, errp); |+ int tmp = *obj; |+ visit_type_enum(v, &tmp, QType_lookup, "QType", name, errp); |+ *obj = tmp; | } Let's use it. >>> void visit_type_%(c_name)s(Visitor *v, %(c_name)s *obj, const char *name, >>> Error **errp) >>> { >>> - visit_type_enum(v, (int *)obj, %(c_name)s_lookup, "%(name)s", name, >>> errp); >>> + int tmp = *obj; >>> + visit_type_enum(v, &tmp, %(c_name)s_lookup, "%(name)s", name, errp); >>> + *obj = tmp; >>> } >>> ''', >>> c_name=c_name(name), name=name) >> >> Same pattern in qapi-visit-core.c, except we name the variable @value >> there. Your choice. > > 'value' sounds consistent. An easy swap on a respin. Okay.