On Mon, 11 May 2009, Øyvind Harboe wrote:

> On Mon, May 11, 2009 at 5:25 PM, Nicolas Pitre <n...@cam.org> wrote:
> > On Mon, 11 May 2009, Øyvind Harboe wrote:
> >
> >> 2009/5/11 Nicolas Pitre <n...@cam.org>:
> >> >
> >> > cc1: warnings being treated as errors
> >> > jtag.c: In function ‘jtag_check_value_mask_callback':
> >> > jtag.c:703: error: cast from pointer to integer of different size
> >> > jtag.c: In function ‘jtag_add_scan_check':
> >> > jtag.c:740: error: cast to pointer from integer of different size
> >>
> >> Is this a 64 bit host?
> >
> > Yes.
> 
> Hmm.... so what's the correct way to cast a void * to an int (keeping only
> as many bits as will fit in an int) on a 64 bit system?

You cast to a long first, like:

diff --git a/src/jtag/jtag.c b/src/jtag/jtag.c
index 0be66c2..b59d02d 100644
--- a/src/jtag/jtag.c
+++ b/src/jtag/jtag.c
@@ -700,7 +700,7 @@ int jtag_check_value_inner(u8 *captured, u8 
*in_check_value, u8 *in_check_mask,
 
 static int jtag_check_value_mask_callback(u8 *in, jtag_callback_data_t data1, 
jtag_callback_data_t data2, jtag_callback_data_t data3)
 {
-       return jtag_check_value_inner(in, (u8 *)data1, (u8 *)data2, (int)data3);
+       return jtag_check_value_inner(in, (u8 *)data1, (u8 *)data2, 
(int)(long)data3);
 }
 
 static void jtag_add_scan_check(void (*jtag_add_scan)(int num_fields, 
scan_field_t *fields, tap_state_t state),
@@ -737,7 +737,7 @@ static void jtag_add_scan_check(void (*jtag_add_scan)(int 
num_fields, scan_field
                if ((fields[i].check_value!=NULL)&&(fields[i].in_value!=NULL))
                {
                        /* this is synchronous for a minidriver */
-                       jtag_add_callback4(jtag_check_value_mask_callback, 
fields[i].in_value, fields[i].check_value, fields[i].check_mask, 
(jtag_callback_data_t)fields[i].num_bits);
+                       jtag_add_callback4(jtag_check_value_mask_callback, 
fields[i].in_value, fields[i].check_value, fields[i].check_mask, 
(jtag_callback_data_t)(long)fields[i].num_bits);
                }
                if (fields[i].allocated)
                {

This however starts to become really ugly and deserves some comment as 
to why such trickery is used.  Even the original code might benefit from 
some explanation for those casts.

> Alternatively I could use a less clever scheme and have a union of int
> & void *...

I'd say clearer and cleaner rather than less clever.  Generated code 
would be the same, except on big endian 64-bit machines where you'd end 
up keeping the top pointer bits instead.  In that case you'd need an 
union definition where a dummy int would need to be inserted as padding.

Probably the cleanest solution would be to encapsulate the two casts 
within a macro, and put a nice comment above the macro definition to 
explain why this is done.  Similar to:

/*
 * We don't care about the real pointer but only the low 32 bits of it
 * for some funky hash lookup.  The double cast removes warnings on 
 * 64-bit machines.
 */
#define PTR_TO_HASH(X) ((int)(long)(x))


Nicolas
_______________________________________________
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development

Reply via email to