This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: casting on 64/32-bit environment
- From: Andrew Haley <aph-gcc at littlepinkcloud dot COM>
- To: "Mitja Ursic" <mitja dot ursic at email dot si>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Mon, 22 Oct 2007 10:23:13 +0100
- Subject: Re: casting on 64/32-bit environment
- References: <20071022065835.68B048B751@www1.email.si>
Mitja Ursic writes:
> On Fri, 12 Oct 2007 at 15:46:14, Andrew Haley wrote:
> > The problem here is that we don't know what you don't understand.
> >
> > If you're casting a pointer to an (32-bit) int, then if you are on a
> > 64-bit system, there will be overflow and some information will be
> > lost. If you're on a 32-bit system then there won't be a problem.
> > This seems obvious: what's the problem?
>
> Sorry for very late replay. My OS is 64 bit (Linux Red Hat 4 WS,
> Update 4, 64- bit). I want to compile a program in 64-bit
> environment but due to casting I don't trust to the compiled
> program. So I want to figure out which steps are necessary to take
> and than to compiled program on 64-bit without casting warnings. So
> if you have any advice what to do I would be happy. Perhapse a part
> of a code would help to figure out what is the cause of my
> problems.
You're casting from a pointer to an integer. This is the wrong thing
to do.
> So, this is my casting warning:
> func.cc: In function `void func()': func.cc:105: warning: cast to pointer from
> integer of different size
> PtrF.h: In constructor `PtrF<Element>::PtrF(Element*) [with Element = el]':
> func.cc:105: instantiated from here PtrF.h:39: warning: cast from pointer to
> integer of different size
>
> Down I give a part of a code:
>
> //FUNC.CC
> void func ()
> {
> ?
> int iel=0;
> ?
> PtrF <EL> el01 = (EL*) iel; //line 105
Don't do this. The answer to your problem is to not cast a pointer to
an integer. If you can explain why you want to do such casting, we'll
be able to tell you how to avoid it.
Andrew.