The Database Managers, Inc.

Contact The Database Managers, Inc.


Use an RSS enabled news reader to read these articles.Use an RSS enabled news reader to read these articles.

W8059 Structure packing size has changed

by Curtis Krauskopf

Q: My application compiles with a warning: W8059 Structure packing size has changed. The warning appears for Borland C++ Builder library files, such as _prolog.h and _epilog.h. What is wrong and how can I remove the warning?

A: I recently saw this warning on an application that I converted from C++ Builder version 4 (BCB4).

Figure 1 shows an example of the warnings I received.

[C++ Warning] _prolog.h(49): W8059 Structure packing size has changed
[C++ Warning] _prolog.h(19): W8059 Structure packing size has changed
[C++ Warning] _epilog.h(32): W8059 Structure packing size has changed
[C++ Warning] _epilog.h(38): W8059 Structure packing size has changed
Figure 1: An example of the warnings I received when compiling the converted application.

The warning means the byte alignment has changed after compiling a header file. The byte alignment is changed with the pack pragma, like this:

#pragma option push -a1 // byte alignment mode

The normal way of restoring the byte alignment is with this pragma:

#pragma option pop

Both pragmas should appear in the same header (.h or .hpp) file.

However, the application I converted did not change the byte alignment in any of the source code!

The Borland Solution

According to the Borland web page that discusses this error, there are two ways to work around this problem:

1) Disable the warning (-w-pck)

2) Surround the headers that change the byte alignment with pack pragmas, like this:

#ifdef __BORLANDC__
# pragma pack(push, 8)
#endif 

#include <map>

#ifdef __BORLANDC__
# pragma pack(pop)
#endif 

In my real-life example, I surrounded all of the #includes in the application with the above conditionally compiled code. The problem went away but I still wasn't satisfied -- all I was doing was covering up the problem.

Finding a Better Solution

I created a new project (from scratch) and copy-pasted the original code (without the Borland-suggested pragma fixes) into the new project. The new project compiled without any warnings!

Digging deeper, I did a text comparison between the two .bpr project files. Figure 2 shows one of the differences that I found.

Click on this image for a full-size version.
Figure 2: Differences found when comparing two .BPR files. Click on the image to see a larger version of the image.

The top line of figure 2 shows the CFLAG1 value for the automatically converted application. The bottom line shows the project that was built from scratch.

The -a option on the line defines the default byte alignment. The converted application uses Double Word alignment (4 byte) and the project built from scratch uses Quad Word (8 byte) alignment.

The real problem is that the Borland C++ Builder header files for <list>, <string> and others assume a Quad Word default alignment.

Since the application I'm converting doesn't care what the word alignment is, I changed the data alignment from Double Word to Quad Word.

How to change a project's byte alignment

In the Borland C++ Builder IDE, open the Project Manager panel by clicking on View | Project Manager or by using the Alt+0 shortcut.

In the Project Manager panel, highlight the project's exe name and then right click it. A context-menu will appear.

How to open the Project Options panel in Borland C++ Builder.
Figure 3: Choose the Options item from the menu.

Choose the Options item from the menu. A Project Options panel appears.

Figure 4: Choose the Options item from the menu.

In the Project Options panel, choose the Advanced Compiler tab .

Notice that the Data Alignment is Double word . This matches the -a4 setting found when comparing the two project files.

Change the Data Alignment to Quad word .

Finally, save the options by clicking on the OK button .

Conclusion

Borland's advice to suppress the warning or use #pragmas around the included files hides the warning. The best solution is to change the default data alignment for the project. Just be careful that the application doesn't require the non-standard data alignment. In the BCB4 application I converted, the data alignment defaulted to Double word when it could have been Quad word to be compatible with Borland C++ Builder 6.

This article was written by Curtis Krauskopf (email at ).

Copyright 2003-2010 The Database Managers, Inc.

Popular C++ topics at The Database Managers:

Services | Programming | Contact Us | Recent Updates
Send feedback to: