Skip to content

implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1 #174

Open
@phaag

Description

Obviously some compiles interpret a 1bit int32_t as negativ.

warning: implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1 [-Wsingle-bit-bitfield-constant-conversion]
KBTREE_INIT(ifTree, nameNode_t, nodeCMP)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../include/kbtree.h:378:2: note: expanded from macro 'KBTREE_INIT'
        __KB_PUT(name, key_t, __cmp)                            \
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
../include/kbtree.h:215:32: note: expanded from macro '__KB_PUT'
                        b->root = s; s->is_internal = 1; s->n = 0;                                      \
                                                    ^ ~

Patch:
Change the type of kbnode in kbtree.h to unsigned int.

typedef struct {
    uint32_t is_internal : 1, n : 31;
} kbnode_t;

This should have no impact.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions