Robby
2010-05-22 14:43:01 UTC
Hello,
Could someone please help me with comparing the contents of a pointer and
NULL.
I don't know why I am confused with this. Pointers can be assigned to NULL
right. And if I want to compare that NULL how do we do it.
Here is the snippet... it compiles but with a warning such as:
MN.c:85: warning: comparison between pointer and integer
The variables "curr_icon_pos, SIZESFLI and Fli" are set in my real program
but did not set them here since they are irrelevant to the issue.
Please note that,
Sometimes the calling function is like this:
=======================================
int main()
{
unsigned short folderIdx = 4;
mn_get_index_to_prev_fli_icon (0, &folderIdx, curr_icon_pos, SIZESFLI, Fli);
return 0;
}
=====================================
and other times its like this where I just assign a NULL as the 2nd parameter:
=======================================
int main()
{
mn_get_index_to_prev_fli_icon (2, NULL, curr_icon_pos, SIZESFLI, Fli);
return 0;
}
=====================================
============================Function implementation
short mn_get_index_to_prev_fli_icon
( unsigned char offset,
unsigned short *icon_idx,
unsigned short curr_icon_pos,
unsigned char arr_size,
unsigned short *array)
{
unsigned char x;
unsigned short rValid = FALSE;
for(x=0; x < arr_size; x++)
{
if(array[x] == curr_icon_pos)
{ rValid = TRUE;
if((*icon_idx) != NULL)
{
*icon_idx = (unsigned short) (x + offset);
}
break;
}
}
return rValid;
}
=========================================
Please note "x" and "arr_size" should be an int but for the time being while
I am porting I left all variables to the their 8 bit MCU's corresponding
width.
I am getting a warning on the following line:
if((*icon_idx) != NULL)
where if the contents of the pointer is not NULL, then I will dereference
the pointer so I can assign a value to it.
all help appreciated!
Thanks
Roberto
Could someone please help me with comparing the contents of a pointer and
NULL.
I don't know why I am confused with this. Pointers can be assigned to NULL
right. And if I want to compare that NULL how do we do it.
Here is the snippet... it compiles but with a warning such as:
MN.c:85: warning: comparison between pointer and integer
The variables "curr_icon_pos, SIZESFLI and Fli" are set in my real program
but did not set them here since they are irrelevant to the issue.
Please note that,
Sometimes the calling function is like this:
=======================================
int main()
{
unsigned short folderIdx = 4;
mn_get_index_to_prev_fli_icon (0, &folderIdx, curr_icon_pos, SIZESFLI, Fli);
return 0;
}
=====================================
and other times its like this where I just assign a NULL as the 2nd parameter:
=======================================
int main()
{
mn_get_index_to_prev_fli_icon (2, NULL, curr_icon_pos, SIZESFLI, Fli);
return 0;
}
=====================================
============================Function implementation
short mn_get_index_to_prev_fli_icon
( unsigned char offset,
unsigned short *icon_idx,
unsigned short curr_icon_pos,
unsigned char arr_size,
unsigned short *array)
{
unsigned char x;
unsigned short rValid = FALSE;
for(x=0; x < arr_size; x++)
{
if(array[x] == curr_icon_pos)
{ rValid = TRUE;
if((*icon_idx) != NULL)
{
*icon_idx = (unsigned short) (x + offset);
}
break;
}
}
return rValid;
}
=========================================
Please note "x" and "arr_size" should be an int but for the time being while
I am porting I left all variables to the their 8 bit MCU's corresponding
width.
I am getting a warning on the following line:
if((*icon_idx) != NULL)
where if the contents of the pointer is not NULL, then I will dereference
the pointer so I can assign a value to it.
all help appreciated!
Thanks
Roberto