There are 3 messages in this thread.
You are currently looking at messages 0 to 3.
Hi, I am porting some code across hardware platform. I got the following warning using the cygming compiler warning: cast increases required alignment of target type I believe this can, say, cast a byte-aligned pointer to a integer-aligned pointer, which can break for stricter processors. Does anyone have experience in casting around byte-alignments and can give me some suggestion/pointer? Thanks
DGG wrote:
> Hi,
>
> I am porting some code across hardware platform.
>
> I got the following warning using the cygming compiler
don't know this compiler but I've seen this warning produced
by gcc.
> warning: cast increases required alignment of target type
If the platform you're porting to does not like unaligned
memory accesses (eg, ARM7), then these warnings are worth
analyzing. They can point to some dirty tricks like:
static uint_8 foo[4];
{
// reading 4 bytes into a 32bit variable
uint_32 bar = *((uint_32 *)foo);
}
While this trick works perfectly on some platforms,
it fails on ARM7 if foo[4] is not word-aligned (where word is 32 bits).
On the other hand, the warning doesn't necessarily indicate a problem,
each warning has to be analyzed individually.
> I believe this can, say, cast a byte-aligned pointer to a
> integer-aligned pointer, which can break for stricter processors.
Not sure I understand this. The warning is there to tell you that
you're casting from one type to another and this 'another' type
is larger in size, which might imply a certain alignment requirement
for it. It is then your responsibility as a developer to ensure
that the variable is properly aligned for such a cast or that
there are no alignment restrictions on the given platform or
get rid of this cast and do things in a different way.
In article <1...@g47g2000cwa.googlegroups.com>, DGG <t...@nectech.co.uk> wrote: >Hi, > >I am porting some code across hardware platform. > >I got the following warning using the cygming compiler > >warning: cast increases required alignment of target type > >I believe this can, say, cast a byte-aligned pointer to a >integer-aligned pointer, which can break for stricter processors. > >Does anyone have experience in casting around byte-alignments and can >give me some suggestion/pointer? The usual advice. Don't do it. Cast are indications of bad code. 1) Casting (sometype *) to (othertype *) is especially evil. Get rid of the casts at the original platform. Retest. Then port. 1) Not always. The casts required by incompetent managers to suppress Sensible Warnings are indicative of incompetent managers. The resulting bad code then is more of a symptom. > >Thanks > -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- like all pyramid schemes -- ultimately falters. a...@spenarnc.xs4all.nl http://home.hccnet.nl/a.w.m.van.der.horst