Cast from a pointer to an integer of a different size
Problem: I received the following warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
Solution: The GNU Compiler Collection (GCC) 4.6.3 issues a warning when you cast a pointer to an integer that is a different size. The [-Wpointer-to-int-cast] warning is enabled by specifying the -Wall compiler option.
Example 1:
if (dir->d_name[0] == '.' &&
dir->d_name[1] == (char) NULL)
continue;
if (dir->d_name[0] == '.' && dir->d_name[1] == '.' &&
dir->d_name[2] == (char) NULL)
continue;
Example 1 corrected code:
if (dir->d_name[0] == '.' &&
dir->d_name[1] == '\0')
continue;
if (dir->d_name[0] == '.' && dir->d_name[1] == '.' &&
dir->d_name[2] == '\0')
continue;
Example 2:
if(ecbp2()->ce2glue != (unsigned int) NULL)
return;
Example 2 corrected code:
if(ecbp2()->ce2glue != 0
return;
Note: The -Wpointer-to-int-cast warning can be valuable;
therefore, do not suppress the warning by using the -Wno-pointer-to-int-cast compiler option unless you are sure that your code is correct.