Cheyenne Forbes de Avapno Cheyenne Forbes de Avapno - 1 year ago 115
C Question

Convert guint8 to uint32_t in C/glib

I cant find a way to convert guint8 to uint32_t in C

I tried:

uint32_t *uint32_value = (uint32_t *)guint8_value;

but it says:

warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
uint32_t *uint32_value = (uint32_t *)guint8_value
warning: assignment makes integer from pointer without a cast [-Wint-conversion]
uint32_t *uint32_value = (uint32_t *)guint8_value

Answer Source

You aren't casting from guint8 to uint32_t.

You are casting from an integer (guint8) to a pointer to an integer (uint32_t*)

The correct code is very simple:

uint32_t uint32_value = guint8_value;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download