开发者

Official C++ language subsets

开发者 https://www.devze.com 2023-01-04 04:36 出处:网络
I mainly use C++ to do scientific computing, and lately I\'ve been restricting myself to a very C-like subset of C++ features; namely, no classes/inheritance except complex and STL, templates only use

I mainly use C++ to do scientific computing, and lately I've been restricting myself to a very C-like subset of C++ features; namely, no classes/inheritance except complex and STL, templates only used for find/replace kinds of substitutions, and a few other things I can't put in words off the top of my head. I am wondering if th开发者_JAVA技巧ere are any official or well-documented subsets of the C++ language that I could look at for reference (as well as rationale) when I go about picking and choosing which features to use.


There is Embedded C++. It sounds mostly similar to what you're looking for.


Google publishes its internal C++ style guide, which is often referred to as such a subset: https://google.github.io/styleguide/cppguide.html . Ben Maurer, whose company reCAPTCHA was acquired by Google, describes it as follows in this post on Quora:

You can basically think of Google's C++ subset as C plus a bit of sugar:

The ability to add methods to structs

Basic single inheritance.

Collection and string classes

Scope based resource management.

They also publish a lint tool, cpplint.py.


Not long ago I listened to this SE-Radio podcast - Episode 152: MISRA with Johan Bezem, which introduces MISRA, standard guidelines for C and C++ to ensure better quality, try looking at it.


The GCC developers are about to allow some C++ features. I'm not aware of any official guidelines, yet, but I am pretty sure that they will define some. Have a look at initial report on the mailing list.


Well, latest developments (TR1, C++0x) in C++ made it very much generic, allowing you to do imperative, OOP or even (limited) functional programming in C++. Libraries like Boost also enable you to do very power declarative template-based meta-programming.

I think Boost is the first thing to try out in C++. It's a comprehensive library, which also includes several modules that enable you to program in functional style (Boost.Functional) or making compile-time declarative meta-programming (Boost MPL).


OpenCL has been using C for writing kernels, but they have recently added (or will soon add) C++ bindings and perhaps Java. OpenCL leaves out a number of performance robbing features of C. Excluded are things like function pointers and recursion. Smart pointers and polymorphism also create overhead.

Restrictions on C: SIMD programming languages

Slightly off topic: Here is a good discussion comparing OpenCL with CUDA using C. OpenCL or CUDA Which way to go?


The SEI CERT C++ Coding Standard gives a list of rules for writing safe, reliable, and secure systems in C++14. This is not a subset of C++ per se, but as a coding standard like the other answers is a subset in effect by avoiding unsafe, undefined, or easily-misused features (including some common to C).

0

精彩评论

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