9

The code is:

           Push(size, (POINTER)(GetCar(i) == term_Null()? 0 : 1));

Here is the C code push returns ABC which is

 typedef POINTER  *ABC
 typedef void * POINTER
 ABC size;
 Push(ABC,POINTER);
 XYZ GetCar(int);
 typedef struct xyz *XYZ;
 XYZ term_Null(); 
 long int i;

What is the reason for the particular warning?

3
  • is sizeof(int)==sizeof(void*) on your platform?
    – Mat
    Apr 18, 2011 at 10:25
  • no the size of int and size of void pointer ** are different. So i am using **long int.
    – thetna
    Apr 18, 2011 at 10:28
  • 1
    so what do you not understand about the message? you're casting an int to a pointer type, you know they have different sizes, and the message tells you that again. seems pretty clear, no?
    – Mat
    Apr 18, 2011 at 10:31

4 Answers 4

21

You can use intptr_t to ensure the integer has the same width as pointer. This way, you don't need to discover stuff about your specific platform, and it will work on another platform too (unlike the unsigned long solution).

#include <stdint.h>

Push(size, (POINTER)(intptr_t)(GetCar(i) == term_Null()? 0 : 1));

Taken from the C99 Standard:

7.18.1.4 Integer types capable of holding object pointers

1 The following type designates a signed integer type with the property that any valid pointer to void can be converted to this type, then converted back to pointer to void, and the result will compare equal to the original pointer:

intptr_t

0

You are trying to cast an integer value (0 or 1) to a void pointer.

This expression is always an int with value 0 or 1: (GetCar(i) == term_Null()? 0 : 1)

And you try casting it to void pointer (POINTER) (typedef void * POINTER).

Which is illegal.

3
  • This is exactly what I said.
    – orlp
    Apr 18, 2011 at 10:29
  • @nightcracker - I agree with your answer, but I saw your post after I posted mine.
    – MByD
    Apr 18, 2011 at 10:30
  • MByD: Oh ok, I personally always click "Load new answers" :)
    – orlp
    Apr 18, 2011 at 10:32
0

Since this question uses the same typedefs as your 32bit to 64bit porting question I assume that you're using 64 bit pointers. As MByd wrote you're casting an int to a pointer and since int isn't 64 bit you get that particular warning.

0

What are you trying to do? Pointers are not integers, and you are trying to make a pointer out of 0 or 1, depending on the situation. That is illegal.


If you were trying to pass a pointer to a ABC containing 0 or 1, use this:

ABC tmp = GetCar(i) == term_Null()? 0 : 1;
Push(size, &tmp);
4
  • i did the one you mentioned here. but still i am getting the same warning. Can you please tell me what else can be the reason?
    – thetna
    Apr 18, 2011 at 10:43
  • Can you give us the full warning, and a bigger chunk of code? You can pastebin them here.
    – orlp
    Apr 18, 2011 at 10:47
  • hi, I typecasted the 0 and 1 as long int, and it worked for me. Thanks for your help
    – thetna
    Apr 18, 2011 at 10:51
  • Push(size, &ABC); is not a valid statement(ABC is a type, not a variable...)
    – MByD
    Apr 18, 2011 at 11:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.