Why is (void *) needed in pointer conversion?

In the following code, why is it needed (VOID *)in the middle of a pointer conversion?

Some definition of context:

#define VOID      void
typedef unsigned char       UINT8;


ErrorDest = (EFI_ACPI_6_0_GENERIC_HARDWARE_ERROR_SOURCE_STRUCTURE *)
            (VOID *)
            ((UINT8 *)Hest + Hest->Header.Length);
+4
source share
2 answers

The only reason I see it is to prevent the compiler from giving warnings about pointer alignment.

UINT8 no alignment requirements.

A struct . . EFI_ACPI_6_0_GENERIC_HARDWARE_ERROR_SOURCE_STRUCTURE - (.. , ) , .

A void* , , , .

+8

, . - .

, this_t* a = (that_t*)b;, . - , ,

this_t* a = (void*)(that_t*)b; // bad, dont do this

, . undefined, - .

EFI_ACPI_6_0_GENERIC_HARDWARE_ERROR_SOURCE_STRUCTURE , uint8_t [], undefined - .

+1

Source: https://habr.com/ru/post/1673274/


All Articles