开发者

How to judge whether a project is a c or c++ project?

wprintf(L"Selecting Audio Input Device: %s\n", 
                            varName.bstrVal);
if(0 == wcscmp(varName.bstrVal, L"IP Camera [JPEG/MJPEG]"))
{
    ...
}

hr = CoCreateInstance(CLSID_SampleGrabber, NULL, CLSCTX_INPROC_SERVER,
                        IID_IBaseFilter, (void **)&pGrabberF);

The above is from a .cpp file ,but as you see its content is quite c-style.

Will you cal开发者_开发百科l it a c or c++ project?


It simply depends how you compile it.

Some code will compile as both, it's considered C++ code if it gets compiled by a C++ compiler.

C is NOT an exact subset of C++ by the way.

Often you can deduce with a fast glance simply by the file's extension, although it's possible to put C code in a .cc extension or .cpp extension and you can also put C++ code in a .c extension, but that would be pretty rare.


I'd call it a C project because I wouldn't be caught dead using C-style string comparison via raw pointer in C++. Exceptions or other stuff would annihilate that code. A correct solution would be to change bstrVal into a BSTR class, which has an operator== overload for wchar_t*.


I'd say it depends on linkage. If it's a library intended to be C linkable, it's C. If it requires C++ to link with, it's C++. If it provides both options, it's both.

If however it's not a library, and it requires a C++ compiler to build, it's a C++ project.

Update0

It's still a matter of linkage. The code you've given will compile under both C and C++.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜