In-depth understanding of C ++ 11 Reading notes

To ensure the stability and compatibility of two
retaining compatibility with C99

Predefined macros
C99 language standard adds some predefined macros, C ++ 11 also adds support for these macros

  • __func__ predefined identifier

  Where the function name of the function is returned, the C ++ 11, the standard even allows its use in the structure of the class or

  • _Pragma operator

  C / C ++ standard, # pragma directive is a pretreatment, some of the information to convey to the outside the standard language compilers, e.g. #pragma once indicates that the header file should be compiled once only
  defined in the C ++ 11 standard the #pragma preprocessing functions with the same operator _Pragma, e.g. _Pragma ( "once");

  • Macro definitions and variable length parameter __VA_ARGS__

  In C99 standard, variable length parameters macro definition refers to the last parameter of the parameter list macro definition replaced ellipsis ellipses, and the predetermined __VA_ARGS__ achieve some predefined macros in the macro can be defined to represent a string
  #define PR (...) printf (__ VA_ARGS__ )

 

  • Connecting string width

  C ++ standard, converting the narrow string (char) to a wide string (wchar_t) the behavior is undefined
  in the standard C ++ 11, when the narrow and wide string connection string, the string will be narrow converted into a wide string, and then connected to the wide string

 

 

Macro __cpluscplus__

   C and C ++ header files mix of typical usage

. 1  #ifidef the __cplusplus
 2  extern  " C " {
 . 3  #endif 
. 4  // some code 
. 5  #ifdef the __cplusplus
 . 6  }
 . 7  #endif

 

   In C ++ 11   __cplusplus is defined as 201103L be used to detect whether the support C ++ 11

#if the __cplusplus <201103L
     #error "Should implemention use C ++. 11" // pre-compiled instructions
 #endif

 

 

Static assertion
  assertion that the return value is always a need to really discriminant put in the statement for exclusion should not have logically designed to force the program when an exception occurs, exit to avoid the program into logic mess


  Assert.h header files define macros affected NDEBUG If the pre-procedure in dealing with this header file NDEBUG has been defined, the assert macro is defined as empty of content, which means assert macro is not working. So, you can in the final when the publisher can use -DNDEBUG close assertions or to #define NDEBUG added to each source file, but this statement must be placed before the #include <assert.h>.

  • Static assertions and static_assert

    We assert assert Runtime
      C ++ 11 standard, introduced static_assert assertions, assertions solving compiled

  static_assert (constant expression, suggesting that the string).

  If the first argument constant expression is true (true or non-zero value), then static_assert do nothing, as if it did not exist, or will cause a compilation error, the error location is static_assert statement row, The second parameter is the error prompt string.

 

noexcept operator modifiers and noexcept

  C ++ 98, the dynamic exception statement throw (int, double), C ++ 11 are deprecated

1 void except_func() throw(int, double){ ... }

   It represents the dynamic function will not throw an exception declared exceptions throw () have been replaced by new noexcept abnormal declaration

  • noexcept

    void except_func () noexcept; represents not throw
    void except_func () noexcept (constant expression); the expression is true not throw an exception; flase thrown

 

Guess you like

Origin www.cnblogs.com/lizhanzhe/p/10978394.html