18 May 2017

A C puzzle

Consider the following C code:

#include <stdio.h>

enum bitmask
{
    bitmask_A = 1,
    bitmask_B = 2,
    bitmask_C = 4
};
typedef enum bitmask bitmask;

struct a_s
{
    bitmask member;
};
typedef struct a_s a_t;

bitmask
f(a_t *arg)
{
    arg->member |= bitmask_B;
    return bitmask_C;
}

int
main()
{
    a_t foo;
    foo.member = bitmask_A;
    foo.member |= f(&foo);
    printf("%d\n", foo.member);
    return 0;
}
What happens?

No comments:

Post a Comment