Thanks for all your guys' replies and constructive suggestions.
Yes, indeed the same time I post here, I decide to modify my codes to
remove the packed attribute and pack the structrue to a continuous
memory myself.
It's just the weird behaviours puzzled me. Becides what I mentioned
above, such as the htons problem, I have tried to compile with new
versions of NDK as
appforce.org suggrested. And sometimes it ran well
while sometimes it crashed. And because I used the modifed NDK version
by Dmitry:
http://www.crystax.net/android/ndk.php. Sometimes when STL
is used it crashed. Seems to be irregular.
Anyway, I should not use packed attribute when define a structure.
On Jul 28, 9:51 pm, David Turner <
di...@android.com> wrote:
> On Wed, Jul 28, 2010 at 6:39 AM, Olivier Guilyardi <
l...@samalyse.com>wrote:
>
> > Since this can cause hard to reproduce bugs, I think it would be smart if
> > the
> > NDK issued a warning or error whenever the packed attribute is used.
>
> This would be a compiler feature, and if there is no specific GCC flag to do
> that (-Wpacked exists but does something really different).
>
>
>
> > Olivier
>
> > On 07/28/2010 03:21 PM, David Turner wrote:
> > > Yes, some CPUs will crash if you try to access a 16-bit value on a
> > > non-aligned 16-bit address (or the same with 32-bits).
> > > This can even change between different ARM-based CPUs. It's an
> > > architectural choice, and there is no way to route around it except
> > > force the compiler to do *very* costly checks on each memory access.
>
> > > Packed structures are a bad idea when writing portable code for this
> > > very reason. You should instead try to access your packed data as an
> > > array of bytes explicitely (or marshal/unmarshal your structs to packed
> > > byte arrays for encryption/decryption purposes).
>
> > >
android-ndk...@googlegroups.com<android-ndk%2Bunsubscribe@googlegr
oups.com>
> > > <mailto:
android-ndk%2Bunsu...@googlegroups.com<android-ndk%252Bunsubscr
i...@googlegroups.com>
> > >
android-ndk...@googlegroups.com<android-ndk%2Bunsubscribe@googlegr
oups.com>
> >
android-ndk...@googlegroups.com<android-ndk%2Bunsubscribe@googlegr
oups.com>
> > .
> > For more options, visit this group at
> >
http://groups.google.com/group/android-ndk?hl=en.- Hide quoted text -