Are #pragma pack() statements no longer needed?

Have a question about our Software Developer Kit? Ask them here.
Post Reply
xenic
Posts: 1185
Joined: Sun Jun 19, 2011 12:06 am

Are #pragma pack() statements no longer needed?

Post 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.
AmigaOne X1000 with 2GB memory - OS4.1 FE
User avatar
broadblues
AmigaOS Core Developer
AmigaOS Core Developer
Posts: 600
Joined: Sat Jun 18, 2011 2:40 am
Location: Portsmouth, UK
Contact:

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

Post 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.
xenic
Posts: 1185
Joined: Sun Jun 19, 2011 12:06 am

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

Post 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.
AmigaOne X1000 with 2GB memory - OS4.1 FE
User avatar
broadblues
AmigaOS Core Developer
AmigaOS Core Developer
Posts: 600
Joined: Sat Jun 18, 2011 2:40 am
Location: Portsmouth, UK
Contact:

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

Post 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.
User avatar
salass00
AmigaOS Core Developer
AmigaOS Core Developer
Posts: 530
Joined: Sat Jun 18, 2011 3:12 pm
Location: Finland
Contact:

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

Post 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.
Post Reply