In the code snippet below, i get this warning - "warning: cast to pointer from integer of different size" in line number 25 which is the 3rd printf i do,
printf("value of a thru struct ptr=%d\n",(unsigned char *)m_arr(ptr_ns_type)[0]);
I dont understand this warning since i do the same thing (except not using macros) in the 2nd printf
printf("value of a thru ptr=%d\n",(unsigned char)*ptr);
for which i dont get any error. could anyone help me in understanding this warning please?
Thanks, Badri.
#include<stdio.h>
struct ns
{
int i;
unsigned char a[2];
};
#define m_arr(whatever) ((struct ns *)whatever)->a
int main()
{
unsigned char arr[2];
unsigned char brr[2];
struct ns ns_type;
struct ns *ptr_ns_type;
arr[0]=192;
arr[1]=168;
brr[0]=172;
brr[1]=188;
ns_type.i=5;
ns_type.a[0]=brr[0];
ptr_ns_type = &ns_type;
unsigned char *ptr=arr;
printf("value of a=%d\n",arr[0]);
printf("value of a thru ptr=%d\n",(unsigned char)*ptr);
printf("value of a thru struct ptr=%d\n",(unsigned char *)m_arr(ptr_ns_type)[0]);
return 0;
}