public inbox for linux-ia64@vger.kernel.org
 help / color / mirror / Atom feed
* [Linux-ia64] ia-64 cast warning??
@ 2001-11-14 18:16 Pereira, D LailaX E
  2001-11-14 18:26 ` Randolph Chung
  2001-11-14 19:03 ` Dan Pop
  0 siblings, 2 replies; 3+ messages in thread
From: Pereira, D LailaX E @ 2001-11-14 18:16 UTC (permalink / raw)
  To: linux-ia64

Hi
Consider the following macro : executing in a program , on linux ia-64
machine: 
ifdef CIRC_DEBUG
#define CBUFSIZE 32768 
#define CHECK_CIRC_ALIGNMENT( A ) \
if (((unsigned int)(circbuff + A))%sizeof(caddr_t)) { A += (sizeof(caddr_t)
- (((unsigned int)(circbuff + A))%sizeof(caddr_t)))/sizeof(unsigned short);
}

#define CIRCADDR( A ) \
CHECK_CIRC_ALIGNMENT(CBptr) \
*(caddr_t *)(circbuff + CBptr) = A; \
CBptr = (CBptr + sizeof(caddr_t)/sizeof(short)) % CBUFSIZE;

#endif


int main(){
  unsigned int volatile* mask;
  unsigned short circbuff[CBUFSIZE];
  unsigned int CBptr;
  unsigned int current;
.....
  CHECK_CIRC_ALIGNMENT(current);
.....
}

I always get the warning : 
warning : cast from pointer to integer of different size  on the line
CHECK_CIRC_ALIGNMENT(current);

when I compile the above program.I want to get rid of the warning.I am not
able to figure out why I get this warning.??
Please let me know 

D'laila


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Linux-ia64] ia-64 cast warning??
  2001-11-14 18:16 [Linux-ia64] ia-64 cast warning?? Pereira, D LailaX E
@ 2001-11-14 18:26 ` Randolph Chung
  2001-11-14 19:03 ` Dan Pop
  1 sibling, 0 replies; 3+ messages in thread
From: Randolph Chung @ 2001-11-14 18:26 UTC (permalink / raw)
  To: linux-ia64

> int main(){
>   unsigned int volatile* mask;
>   unsigned short circbuff[CBUFSIZE];
>   unsigned int CBptr;
>   unsigned int current;
> .....
>   CHECK_CIRC_ALIGNMENT(current);
> .....
> }
> 
> I always get the warning : 
> warning : cast from pointer to integer of different size  on the line
> CHECK_CIRC_ALIGNMENT(current);

circbuff is an unsigned short *, you are casting it to an unsigned int.
Cast it to unsigned long or uintptr_t instead.

randolph
-- 
   @..@                                         http://www.TauSq.org/
  (----)
 ( >__< )
 ^^ ~~ ^^


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Linux-ia64] ia-64 cast warning??
  2001-11-14 18:16 [Linux-ia64] ia-64 cast warning?? Pereira, D LailaX E
  2001-11-14 18:26 ` Randolph Chung
@ 2001-11-14 19:03 ` Dan Pop
  1 sibling, 0 replies; 3+ messages in thread
From: Dan Pop @ 2001-11-14 19:03 UTC (permalink / raw)
  To: linux-ia64


On Wed, 14 Nov 2001, Pereira, D LailaX E wrote:

> Consider the following macro : executing in a program , on linux ia-64
> machine: 
> ifdef CIRC_DEBUG
> #define CBUFSIZE 32768 
> #define CHECK_CIRC_ALIGNMENT( A ) \
> if (((unsigned int)(circbuff + A))%sizeof(caddr_t)) { A += (sizeof(caddr_t)
> - (((unsigned int)(circbuff + A))%sizeof(caddr_t)))/sizeof(unsigned short);
> }
> 
> #define CIRCADDR( A ) \
> CHECK_CIRC_ALIGNMENT(CBptr) \
> *(caddr_t *)(circbuff + CBptr) = A; \
> CBptr = (CBptr + sizeof(caddr_t)/sizeof(short)) % CBUFSIZE;
> 
> #endif
> 
> 
> int main(){
>   unsigned int volatile* mask;
>   unsigned short circbuff[CBUFSIZE];
>   unsigned int CBptr;
>   unsigned int current;
> .....
>   CHECK_CIRC_ALIGNMENT(current);
> .....
> }
> 
> I always get the warning : 
> warning : cast from pointer to integer of different size  on the line
> CHECK_CIRC_ALIGNMENT(current);
> 
> when I compile the above program.I want to get rid of the warning.I am not
> able to figure out why I get this warning.??

The reason of the warning is OBVIOUS: you are converting a pointer
value (circbuff + current), which is a 64-bit value, to unsigned int,
which is a 32-bit type.  The compiler is warning you that you may lose
significant bits in this conversion, and this is the case, indeed, on
Linux-ia64.

As you have already been told, if you need to make such conversions,
use the type uintptr_t, defined in <stdint.h>, instead of some
arbitrary, hard coded integer type.

Dan 



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2001-11-14 19:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2001-11-14 18:16 [Linux-ia64] ia-64 cast warning?? Pereira, D LailaX E
2001-11-14 18:26 ` Randolph Chung
2001-11-14 19:03 ` Dan Pop

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox