Synopsis: | Pointer to and from integer conversions shall not be used. For instance on 64-bit x86 processors the size of an integer is 32-bits while the pointer is 64-bits. Therefore converting a pointer to an integer will discard part of the address. |
Language: | C |
Severity Level: | 4 |
Category: | Conversions |
Description: |
Justification Since such conversions involve implementation defined and undefined behavior, it is safer to avoid their use. Example 1 int i; int *ip; i = (int)ip; /* WRONG */ ip = (int *)i; /* WRONG */ Example 2 static void ccbb_f(void *p_base) { unsigned int offset = 0x10; char *p_address = (char*)((unsigned int)p_base + offset); /* WRONG */ } static void ccbb_f(void *p_base) { unsigned int offset = 0x10; char *p_address = (char*)p_base + offset; /* RIGHT */ } |