[C Programming] - How to create a typedef for a union in C | SheCodes

[C Programming] - How to create a typedef for a union in C to refer to float bit fields as type alias

Learn how to define a typedef for a union in C to create a type alias for float bit fields

👩‍💻 c Code instructions

// Here we declare some global variables used later in the programme volatile int32_t dividend_int32 = 20000; volatile float dividend_float = 20000.0; volatile int32_t divisor_int32 = 77; volatile float divisor_float = 77.0; volatile int32_t reciprocal_shift16 = 851; // Here we declare some functions used later in the programme float div77_fp(float dividend, float divisor) { return dividend/divisor; } int32_t div77_int(int32_t dividend, int32_t divisor) { return dividend/divisor; } int32_t div77_int_nodiv(int32_t dividend, int32_t reciprocal_shift16) { // This is integer division implemented using a multiply and // shift rather than a division operation return (dividend*reciprocal_shift16) >> 16; } * Write a typedef declaration such that we can refer to the union * declared above using the type alias "float_fields".