Closed GoogleCodeExporter closed 8 years ago
Thanks for the report.
This one's a thorny issue. Alignment varies depending on processor architecture
so what's probably needed is to step away from the simple system I'm currently
using and develop a more complex processor-dependent system. Unfortunately this
will also make the system more awkward to port to new platforms but it's
probably necessary in the long run. Added to this is the complication that C
doesn't even guarantee to pack structures in any specific way.
Original comment by zik.sale...@gmail.com
on 27 Jul 2010 at 8:40
To be precise structure packing is compiler dependent, not processor
architecture.
The processor architecture maybe place some limits on the choices the compiler
has.
You are right that the method to pack structures is not part of any
specification.
But, in practice it's done, almost universally, the same by most popular
compliers.
Usually the main difference comes from the initial alignment size, then usually
packing is done in a standard way.
I come from a Unix and Windoze background, which means I'm familiar with GCC,
Sun Compiler, Visual C, etc.
These compilers all work the same once you know the alignment size.
I have no experience in the embedded space, but if you use GCC then I would
think you would be safe.
Currently in PicoC sharing structures between interpreted and native code is a
big no no.
It will work for some very simple cases, but otherwise BOOM.
Original comment by duncan.f...@gmail.com
on 27 Jul 2010 at 9:47
Scheduled for release 2.0
Original comment by zik.sale...@gmail.com
on 27 Jul 2010 at 3:10
After testing on as many platforms as I could, I made some improvements.
To verify each platform I wrote a program to generate very large random
structures and compared offsets.
Original comment by duncan.f...@gmail.com
on 1 Aug 2010 at 3:08
Attachments:
Duncan - that's not 100% correct.
Some architectures do not allow unaligned access to structure elements, so
there are limitations on what options are available to the compiler for that
platform, in terms of structure member-alignment.
Original comment by Alexande...@gmail.com
on 10 Oct 2010 at 3:00
Alexander, to me it's not clear what part you disagree with.
I'm aware unaligned access is not allowed on some architectures. This is
exactly why I worked to fix the incorrect alignment issue. As I mentioned
structure packing is in fact done in a standard way, regardless of whether
misaligned reads are allowed.
Perhaps my explanation was not clear enough for you. My descriptions were very
brief, perhaps reading the code might make it a little clearer.
Original comment by duncan.f...@gmail.com
on 11 Oct 2010 at 10:23
I've spent some time thinking about this one and I've come up with a method
which I hope will be fairly portable across architectures and is still fairly
simple.
I work out the alignments of all the major data types for the target
architecture during program initialisation. Structures are padded to the
alignment of the largest member alignment. I think this is correct for x86 and
should be correct for most other architectures. It's conservative so even if
not correct it shouldn't be harmful.
"Fixed" in r532.
Original comment by zik.sale...@gmail.com
on 15 Feb 2011 at 4:33
Marking as fixed for now.
Original comment by zik.sale...@gmail.com
on 15 Feb 2011 at 4:33
Original issue reported on code.google.com by
duncan.f...@gmail.com
on 27 Jul 2010 at 6:09