Casting twice in the same line

后端 未结 3 871
广开言路
广开言路 2021-02-07 12:19

I saw this code in project.

b\'s type is void*:

void *b = ...;
int a = (int) (unsigned long) b;

Is this line

3条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-07 12:57

    I see this in my project too.

    For my case, the content of 'b' is populated by other sources/middleware used for inter-process communication.

    Once 'b' is populated, the program will get the contents of 'b' with a cast to the correct field 'a'. the application then uses 'a' for processing.

    My project uses char* instead of void* though.

提交回复
热议问题