Hello every one. Please see if you can help. The question is not about
packing and alignment. It is about the use of qualifier __unaligned on
double indirection.

The line "(*((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 qualifier
__unaligned workd fine with one level of indirection, as in:
"((__unaligned something*) thing)->member;" but it breaks in
statement:


"(*((__unaligned something**) thing))->member;"


In above statement, after the first dereferrencing, the pointer is
actually aligned. But that seems to be irrelevant.


Is there a pointer-manipulation work-around for this, please?


My second question for your help is the emulator cpu. Windows mobile 6
SDK Refresh seems to install only ARM processor. Are there emulators
using Intel processor? Where can I get them?

Thank you.
Zorro.

Re: Qualifier __unaligned on pointer to pointer by Igor

Igor
Sat Jul 26 15:34:59 CDT 2008

"Zorro" <zorabih@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 about
> packing and alignment. It is about the use of qualifier __unaligned on
> double indirection.
>
> The line "(*((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 qualifier
> __unaligned workd fine with one level of indirection, as in:
> "((__unaligned something*) thing)->member;" but it breaks in
> statement:
>
>
> "(*((__unaligned something**) thing))->member;"

Perhaps you need something like

( (__unaligned something*)(*(something**)thing) )->member;

--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925



Re: Qualifier __unaligned on pointer to pointer by Zorro

Zorro
Sat Jul 26 16:24:04 CDT 2008

On Jul 26, 3:34=A0pm, "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 about
> > packing and alignment. It is about the use of qualifier __unaligned on
> > double indirection.
>
> > The line =A0 "(*((something**) thing))->member;" works fine on Intel an=
d
> > Motorola chips and a number of compilers. However, with ARM chip,
> > using Visual C++ it breaks due to datatype misalignment. The qualifier
> > __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.

Thank you.
Z.


Re: Qualifier __unaligned on pointer to pointer by Alf

Alf
Sat Jul 26 17:02:53 CDT 2008

* 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 about
>>> packing and alignment. It is about the use of qualifier __unaligned on
>>> double indirection.
>>> The line "(*((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 qualifier
>>> __unaligned workd fine with one level of indirection, as in:
>>> "((__unaligned something*) thing)->member;" but it breaks in
>>> statement:
>>> "(*((__unaligned something**) thing))->member;"
>> Perhaps you need something like
>>
>> ( (__unaligned something*)(*(something**)thing) )->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 use
bit-fields.

Also, while __unaligned is a red flag that says something is seriously wrong
with the approach, the casts, and especially C style casts, are flags that 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 are much
higher. Also, it will then be much more maintainable.

But regarding your /technical/ problem, how about doing as Caesar, divide and
conquer.

typedef Something UNALIGNED* PSomething;
typedef SomethingPtr UNALIGNED* PPSomething;

Disclaimer: I haven't tried this. Advice: don't do it, instead do as suggested
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?

Re: Qualifier __unaligned on pointer to pointer by Liviu

Liviu
Sat Jul 26 17:20:21 CDT 2008

"Zorro" <zorabih@gmail.com> wrote
On Jul 26, 3:34 pm, "Igor Tandetnik" <itandet...@mvps.org> wrote:
> "Zorro" <zora...@gmail.com> wrote in message
>
>>> Hello every one. Please see if you can help. The question is not
>>> about packing and alignment. It is about the use of qualifier
>>> __unaligned on double indirection.
>>>
>>> The line "(*((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
>>> qualifier __unaligned workd fine with one level of indirection, as
>>> in: "((__unaligned something*) thing)->member;" but it breaks in
>>> statement: "(*((__unaligned something**) thing))->member;"
>>
>> Perhaps you need something like
>>
>> ( (__unaligned something*)(*(something**)thing) )->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.

You have at least two variables in the picture - the object itself, plus
the pointer to it - and it's not clear which one is unaligned. Igor's
reply is correct for the case where the object is unaligned (which was
the natural assumption given your reference to the single indirection
case). If both are unaligned, then something like
"(*((something __unaligned * __unaligned *) thing))->member;"
should/might work. If that still doesn't work, then try and do it in
separate steps (first get the pointer, then use it) which should work if
"one level of indirection works" indeed.

Cheers,
Liviu





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.