Re: Qualifier __unaligned on pointer to pointer by Zorro
Zorro
Sat Jul 26 17:24:54 CDT 2008
On Jul 26, 5:04=A0pm, "Alf P. Steinbach" <al...@start.no> wrote:
> * Zorro:
>
>
>
>
>
> > On Jul 26, 3:34 pm, "Igor Tandetnik" <itandet...@mvps.org> wrote:
> >> "Zorro" <zora...@gmail.com> wrote in message
>
> >>news:ec825e11-6d05-4413-a26b-97ce427847cf@l42g2000hsc.googlegroups.com
>
> >>> Hello every one. Please see if you can help. The question is not abou=
t
> >>> packing and alignment. It is about the use of qualifier __unaligned o=
n
> >>> double indirection.
> >>> The line =A0 "(*((something**) thing))->member;" works fine on Intel =
and
> >>> Motorola chips and a number of compilers. However, with ARM chip,
> >>> using Visual C++ it breaks due to datatype misalignment. The qualifie=
r
> >>> __unaligned workd fine with one level of indirection, as in:
> >>> "((__unaligned something*) thing)->member;" but it breaks in
> >>> statement:
> >>> =A0 =A0 =A0 =A0 =A0"(*((__unaligned something**) thing))->member;"
> >> Perhaps you need something like
>
> >> ( =A0(__unaligned something*)(*(something**)thing) =A0)->member;
>
> > Thank you for trying to help. I used unaligned as you are suggesting,
> > and in all different forms (unaligned appearing in both locations,
> > only one like yours, etc.) and it always does the same thing (breaks).
> > Since it does work for one level of indirection, I am hoping there is
> > a work-around, like your suggestion that will tell the compiler to
> > generate code as needed for more levels of indirection.
>
> The general solution is to not use packing and alignment to achieve some
> externally imposed layout.
>
> Instead, use explicit conversion to/from array of unsigned char, and/or u=
se
> bit-fields.
>
> Also, while __unaligned is a red flag that says something is seriously wr=
ong
> with the approach, the casts, and especially C style casts, are flags tha=
t say
> something is very ungood about the implementation of the approach. If you=
avoid
> these "features" then the chances of ending up with working, good code ar=
e much
> higher. Also, it will then be much more maintainable.
>
> But regarding your /technical/ problem, how about doing as Caesar, divide=
and
> conquer.
>
> =A0 =A0 typedef Something UNALIGNED* =A0PSomething;
> =A0 =A0 typedef SomethingPtr UNALIGNED* PPSomething;
>
> Disclaimer: I haven't tried this. Advice: don't do it, instead do as sugg=
ested
> above.
>
> Cheers, & hth.,
>
> - Alf
>
> --
> A: Because it messes up the order in which people normally read text.
> Q: Why is it such a bad thing?
> A: Top-posting.
> Q: What is the most annoying thing on usenet and in e-mail?- Hide quoted =
text -
>
> - Show quoted text -
It worked, and seems to be the key solution to similar issues that I
will run into for this project.
Thank you very much for your help, indeed.
Z.