views:

833

answers:

4

I'm not seeing any real advantages, other than the fact that you have a C++ syntax, and with it, things like pointers and destructors.

A: 

I don't think comparing different flavors of C++ to each other is the same question as comparing C++ to C#. C# is a very different beast compared to the differences between different flavors of C++.

EBGreen
does he ask about c++.net?
Johannes Schaub - litb
That is true. But even so, I don't see a reason to use Microsoft's C++ over C#. Although I do see reasons to use standard C++ over C# or C# over standard C++.
Thomas Owens
i see reasons for companies to use c++.cli. they don't have to port too much, and they still have access to all of .net.
Johannes Schaub - litb
@litb I don't know, does he?
EBGreen
(assuming they already have a standard c++ application)
Johannes Schaub - litb
EBGreen, i think he should change his question to state the matter :)
Johannes Schaub - litb
@Thomas If you see the reasons for using one or the other, then you are already well on the way to a good answer. It really depends on what you plan to be doing.
EBGreen
+2  A: 

One extension I've found useful is the following construct, utilized by the D3DMATRIX structure in DirectX's d3d9types.h:

typedef struct _D3DMATRIX {
    union {
        struct {
            float        _11, _12, _13, _14;
            float        _21, _22, _23, _24;
            float        _31, _32, _33, _34;
            float        _41, _42, _43, _44;

        };
        float m[4][4];
    };
} D3DMATRIX;

It uses an MSVC extension of an anonymous struct inside an anonymous union (I forget what the technical name for this is), allowing you to access the matrix members either through an explicit name myMatrix._12 or via indexing myMatrix.m[0][1].

Of course, this is just syntactic sugar, and it's much better to have standards-conforming C/C++ than some sugar.

Adam Rosenfield
So what is actually the advantage of myMatrix._12 notation? And btw. I smell index off by one if you start messing the two of them, which you need to do as soon as you are iterating through it.
ypnos
+6  A: 

I think you're referring to C++/CLI and comparing it to C#. C++/CLI isn't a 'flavor' of C++. It's an entirely new language with entirely different standard libraries and entirely different conventions.

At work we find that C++/CLI is valuable as a glue language between C++ and .NET, but we don't use it for anything besides interface glue - C# has enormous advantages over C++ in all other applications.

If you're referring to MS C++ extensions like what Adam describes, there's no reason not to use them if they make your job easier.

Dustin Getz
+10  A: 

If you're talking about why you would use C++/CLI over C#, I think the main reasons are that:

  1. it might be more natural for C++ developers (though I think this is probably not true)
  2. C++/CLI has very nice capabilities for bridging the native and managed environments (using the 'IJW' - It Just Works - technology)

I think that Herb Sutter probably gives the best overview:

A Design Rationale for C++/CLI

If you want to know why you might want to use native C++ over C#/.NET, this boils down to why you would want a managed environment (safety, easier development) over native code (absolute control, possibly speed advantages). There are arguments for each, and the answer really depends on what you want to develop and what your market might be.

Michael Burr