Are #pragma pack() statements no longer needed?

Have a question about our Software Developer Kit? Ask them here.

Are #pragma pack() statements no longer needed?

Postby xenic » Mon Dec 11, 2017 7:19 pm

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
xenic
 
Posts: 1147
Joined: Sun Jun 19, 2011 1:06 am

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

Postby broadblues » Tue Dec 12, 2017 5:47 am

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.
User avatar
broadblues
AmigaOS Core Developer
AmigaOS Core Developer
 
Posts: 538
Joined: Sat Jun 18, 2011 3:40 am
Location: Portsmouth, UK

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

Postby xenic » Wed Dec 13, 2017 7:16 pm

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
xenic
 
Posts: 1147
Joined: Sun Jun 19, 2011 1:06 am

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

Postby broadblues » Wed Dec 13, 2017 9:03 pm

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
broadblues
AmigaOS Core Developer
AmigaOS Core Developer
 
Posts: 538
Joined: Sat Jun 18, 2011 3:40 am
Location: Portsmouth, UK

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

Postby salass00 » Thu Dec 14, 2017 11:29 am

@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.
User avatar
salass00
AmigaOS Core Developer
AmigaOS Core Developer
 
Posts: 506
Joined: Sat Jun 18, 2011 4:12 pm
Location: Finland


Return to SDK Support

Who is online

Users browsing this forum: No registered users and 2 guests