Warning C4103 in Visual Studio 2010 is broken?

A few days ago my colleagues came across a very nasty bug caused by a header changing struct alignment (my apologies, this post is only available in Russian at the moment). In short, we were never supposed to have that problem in the first place as compiler should have given us a warning C4103.

But it didn’t. (Best said in Jeremy Clarkson voice).

Consider this header

// dummyHeader.h
#pragma  pack(push, 1)
			struct Dummy
				int a;
				char b;
				short c;
// oops, #pragma pack(pop) is missing..

The problem is fairly obvious – it changes struct alignment without restoring it back. Side effects of it include scary debug runtime check assertion, buffer overruns, sudden hard disk formatting and reactor core meltdowns.

Let’s include this header:

#include "DummyHeader.h"

#include "SomeOtherHeader.h"

And compile. As expected, compiler is not happy at all:

warning C4103: ‘test.cpp’ : alignment changed after including header, may be due to missing #pragma pack(pop)

Now, do the magic trick of changing the order in which headers are included

#include "SomeOtherHeader.h"
#include "DummyHeader.h"

Now it compiles without warnings.

I played with it for hours and could only get compiler to produce a warning when the offending header was on the top of the list.

I have only one thing to say – WTF?

Microsoft Visual Studio 2010
Version 10.0.30319.1 RTMRel

Visual Studio SP1Rel appears to be free of this problem

  1. MSVC 2010 SP1Rel – warning в обоих случаях …

    • Так, понятно куда копать.
      А то у нас все девелоперские машины, похоже, до SP1 еще не проапгрейчены.

    • Подтверждаю. проверил дома, все пучком.

      Забавно, где еще подобная фигня вылезала. Обрадую своих в понедельник, что нам нужен срочный апгрейд.

Leave a Comment

NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

16 visitors online now
0 guests, 16 bots, 0 members
Max visitors today: 23 at 12:39 am UTC
This month: 57 at 04-16-2021 08:12 am UTC
This year: 57 at 04-16-2021 08:12 am UTC
All time: 332 at 11-22-2019 03:23 am UTC