Bug 779 - Union casting in util/ub_event.c and util/ub_event_pluggable.c is non-portable
Union casting in util/ub_event.c and util/ub_event_pluggable.c is non-portable
Product: unbound
Classification: Unclassified
Component: server
Other other
: P5 normal
Assigned To: unbound team
: 799 (view as bug list)
Depends on:
  Show dependency treegraph
Reported: 2016-06-14 12:14 CEST by Richard Lloyd
Modified: 2016-07-20 14:11 CEST (History)
3 users (show)

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description Richard Lloyd 2016-06-14 12:14:22 CEST
When compiling unbound 1.5.9 with HP-UX 11.31 using HP's ANSI C compiler, the union casting used in util/ub_event.c and util/ub_event_pluggable.c causes compilation failures because that compiler doesn't support such casting.

For example, util/ub_event.c defines four macros (AS_EVENT_BASE(x), AS_UB_EVENT_BASE(x), AS_EVENT(x) and AS_UB_EVENT(x)) that cast a union type that isn't supported by HP's ANSI C and produce this compiler error:

cc: "util/ub_event.c", line 264: error 1527: Incompatible types in cast: Must cast from scalar to scalar or to void type.
[19 other identical errors later in the file]

The similar macros (AS_MY_EVENT_BASE(x) and AS_MY_EVENT(x)) in util/ub_event_pluggable.c also produced the same sort of error. I'm not sure if union casting is a gcc-only feature, but I suspect other non-gcc compilers may have a similar issue.
Comment 1 Wouter Wijngaards 2016-06-14 12:24:58 CEST
Hi Richard,

I did not know it was nonportable.  It was introduced because of gcc type-punned pointer warnings I think.

Fixed in the code repository.  Thank you for the report.

Best regards, Wouter
Comment 2 Wouter Wijngaards 2016-07-20 14:11:21 CEST
*** Bug 799 has been marked as a duplicate of this bug. ***