Page 1 of 1

Are #pragma pack() statements no longer needed?

PostPosted: Mon Dec 11, 2017 7:19 pm
by xenic
I noticed that a lot of SDK header files don't have " #pragma pack() " statements. For example:
SDK:Include/include_h/libraries/ahi_sub.h
SDK:Include/include_h/libraries/application.h
SDK:Include/include_h/libraries/blankermodule.h
SDK:Include/include_h/libraries/bzip2.h
SDK:Include/include_h/libraries/docky.h
SDK:Include/include_h/libraries/filesysbox.h
SDK:Include/include_h/libraries/screenblanker.h
SDK:Include/include_h/libraries/z.h

Can I assume that we don't need the " #pragma pack() " stuff in our includes any more? If not, then a lot of SDK header files (more than the above examples) need to be updated.

Re: Are #pragma pack() statements no longer needed?

PostPosted: Tue Dec 12, 2017 5:47 am
by broadblues
That would be a poor assumption.

Just because one header doesn't have them doesn't mean you can omit them from one that does.

During my early work on PPaint there were some coppies of system structures for forward compatabilty (at the time PPAint was originally written), being 68k SASC based code there was no pragma pack statements around those, so they didn't align correctly when compiled with gcc, giving odd crashes that took a bit of head scratching to fix until I realised and added the pragmas.

All those includes you mention are recent, post PPC includes, so no need for the pragma pack, as native alignment will be correct.

Re: Are #pragma pack() statements no longer needed?

PostPosted: Wed Dec 13, 2017 7:16 pm
by xenic
broadblues wrote:That would be a poor assumption.

Just because one header doesn't have them doesn't mean you can omit them from one that does.

During my early work on PPaint there were some coppies of system structures for forward compatabilty (at the time PPAint was originally written), being 68k SASC based code there was no pragma pack statements around those, so they didn't align correctly when compiled with gcc, giving odd crashes that took a bit of head scratching to fix until I realised and added the pragmas.

All those includes you mention are recent, post PPC includes, so no need for the pragma pack, as native alignment will be correct.

I've been putting "#pragma pack()" statements in my headers since I started programming with OS4.x but when I noticed that some SDK headers don't have them, I was just wondering if I could stop using them in my programs.

Re: Are #pragma pack() statements no longer needed?

PostPosted: Wed Dec 13, 2017 9:03 pm
by broadblues
There no reason at all, nor, I think, has there ever been, to put them in a programs private headers, assuming all parts of that program are compiled under OS4.

You *might* need them if that OS4 prgram can have 68k pugins / libs or vice verca and those plugins share data via a structure.

You might also need them if you write data to disk as a raw structure and then that data might be read back by a 68k app, or any context where the alignment might not be guarenteed.

Re: Are #pragma pack() statements no longer needed?

PostPosted: Thu Dec 14, 2017 11:29 am
by salass00
@xenic

The latest AHI includes in the AmigaOS source repo do now have the standard alignment pragma statements (also optional AmigaOS namespace for C++). Most likely they were left out before because no-one thought to add them and the lack of them didn't cause any problems because none of the public AHI structures have non-aligned long words or pointers.