Anthony
Anthony

Reputation: 12407

Can Visual Studio 2010 ignore specific pragmas?

I have literally hundreds of C++ source files used by many projects. They were written quite a while back, and they are all wrapped in packing pragmas:

#pragma pack(push, 1)
/* Code here ... */
#pragma pack(pop)

I have been put in charge of porting to x64. Amongst the many changes that need to be made, one is the requirement for a 16-byte aligned stack for Windows API calls. After some analysis of our system, we've determined that 1-byte structure alignment is not necessary and won't have any adverse affects on the system. I need to get rid of the 1-byte packing.

I know I can do a quick find/replace on all the files and just strip them out. This is an OK solution; I'm perfectly happy to do this if it's the only way. However, if I can avoid having to check in a revision which involves changes to literally hundreds of source files, and all the conflicts that might go with it, then that would be preferable.

Is there a way to get the Microsoft Compiler to ignore the #pragma pack?

Upvotes: 1

Views: 314

Answers (1)

Timo Geusch
Timo Geusch

Reputation: 24351

As far as I know, there is no way to disable #pragmas when using MSVC.

What I would probably do is write a script in a language that is well suited to text processing (I'd probably use Ruby, but Python, Perl, sed should all do the job) and simply use that to comment out or remove the #pragma pack lines. This should be comparatively easy as the #pragmas are going to be the only statement on a give line of code, and the script languages do usually include functionality to iterate through a set of directories.

Upvotes: 3

Related Questions