I've been working on my first XS extension, a C++ extension that calculates relative quality of different translations. After some frustrations and false starts it appears to be working fine now. It only compiles with MSVC 2003 .NET, but it's passing all its tests and the benchmarking I've been doing looks good, so I'm happy for the moment.

One problem I had initially was that the xsubpp output would not compile, complaining that cstdio.h and several other standard headers have syntax errors in them. That's odd, since these are standard headers distributed with the compiler -- it seems highly unlikely that they contain syntax errors, even if this is a Microsoft product.

I finally fixed it by putting the C++ header #includes first in the file and the standard Perl C header #includes after them. (and by making sure that the XS output was recognized as C++ rather than C, but that's tangential to my question). Other monks have run into very similar problems (here and here), and at least one person independently found the same solution.

Great. Problem solved. But why? Why should there be this restriction on the order of #included headers in XS modules? I can keep on using this solution in future XS extensions, but I'll feel like a member of some cargo cult if I keep doing it without understanding the why. So does any monk out there have a clue what's really going on here that the order of #includes has this effect?

--DrWhy

"If God had meant for us to think for ourselves he would have given us brains. Oh, wait..."


In reply to Why does order of #include's matter in XS file for C++ extensions under Windows? by DrWhy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.