C/C++知识扩充_cctype和climits的用法


cctype和climits的用法

C/C++语言知识扩充_cctype和climits的用法 - Essence - ACM_Of_Essence
 

一、 cctype中通常包括一些常用函数的判断,如某个字符是否为大写,用isupper()如果参数是大写字母,函数返回true, 还有像isalnum(),如果参数是字母数字,即字母或者数字,函数返回true.下面我们通过一个小示例来查看输出结果:

cout << "i is : " << isupper('b') << "\n";

输出:i is : 0

如果把参数改为'B',则会输出:i is : 1 其它函数的用法见下列表:

函数名称   返回值

isalnum()  如果参数是字母数字,即字母或者数字,函数返回true

isalpha()   如果参数是字母,函数返回true

isblank()   如果参数是水平制表符或空格,函数返回true

iscntrl()     如果参数是控制字符,函数返回true

isdigit()     如果参数是数字(0-9),函数返回true

isgraph()   如果参数是除空格之外的打印字符,函数返回true

islower()    如果参数是小写字母,函数返回true

isprint()      如果参数是打印字符(包括空格),函数返回true

ispunct()    如果参数是标点符号,函数返回true

isspace()   如果参数是标准空白字符,如空格、换行符、水平或垂直制表符,函数返回true

isupper()   如果参数是大写字母,函数返回true

isxdigit()     如果参数是十六进制数字,即0-9、a-f、A-F,函数返回true

tolower()    如果参数是大写字符,返回其小写,否则返回该参数

toupper()   如果参数是小写字符,返回其大写,否则返回该参数

二、操作符sizeof和limits

C语言的数据类型有四种:整形、浮点型、指针、聚合类型(数组、结构等),其中整形家族的变量包括:char, int, short, long, enum等。浮点数家族包括float, double等。limits.h头文件对整形家族变量范围进行了宏定义。float.h定义了FLT_MAX, FLT_MIN, DBL_MAX, DBL_MIN .
对类型名(如int)使用sizeof操作符时,应将名称放在括号中:cout<<sizeof(float)<<endl;

但对变量名使用该操作符,括号是可选的:cout<<sizeof myAge<<endl;

头文件climits定义了符号常量来表示类型的限制。

#include<iostream>

#include<climits>

using namespace std;

int main(){

int n_int = INT_MAX;

short n_short = SHRT_MAX;

long n_long = LONG_MAX;

cout<<"int is "<<sizeof(int)<<" bytes.\n";

cout<<"short is "<<sizeof(short)<<" bytes.\n";

cout<<"long is "<<sizeof(long)<<" bytes.\n\n";

cout<<"Maximum values:\n";

cout<<"int: "<<n_int<<endl;

cout<<"short: "<<n_short<<endl;

cout<<"long: "<<n_long<<"\n\n";

cout<<"Minimum int value= "<<INT_MIN<<endl;

cout<<"bits per byte= "<<CHAR_BIT<<endl;

return 0;

}  

输出:

int is 4 bytes.

short is 2 bytes.

long is 4 bytes.

Maximum values:

int: 2147483647

short: 32767

long: 2147483647

Minimum int value= -2147483648

bits per byte= 8

climits中包括了一些对常量的定义,如int的最大最小值,long的最大最小值等。


C/C++语言知识扩充_cctype和climits的用法 - Essence - ACM_Of_Essence
In file included from D:\TS_Master\TSMaster\Configuration\TOSUN\TSMaster\MiniProgram\Build\CCode7142\CCode7142Extern.cpp:7: In file included from C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/vector:325: In file included from C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/__format/formatter_bool.h:20: In file included from C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/__format/formatter_integral.h:35: In file included from C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/locale:202: In file included from C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/__locale:36: C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/__support/win32/locale_win32.h:95:12: error: unknown type name '_locale_t'; did you mean 'locale_t'? 95 | locale_t(_locale_t __xlocale, const char* __xlocale_str) | ^ C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/__support/win32/locale_win32.h:91:7: note: 'locale_t' declared here 91 | class locale_t { | ^ C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/__support/win32/locale_win32.h:140:12: error: unknown type name '_locale_t'; did you mean 'locale_t'? 140 | operator _locale_t() const { return __locale_; } | ^ C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/__support/win32/locale_win32.h:91:7: note: 'locale_t' declared here 91 | class locale_t { | ^ C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/__support/win32/locale_win32.h:149:3: error: unknown type name '_locale_t'; did you mean 'locale_t'? 149 | _locale_t __locale_; | ^ C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/__support/win32/locale_win32.h:91:7: note: 'locale_t' declared here 91 | class locale_t { | ^ C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/__support/win32/locale_win32.h:149:13: error: field has incomplete type 'locale_t' 149 | _locale_t __locale_; | ^ C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/__support/win32/locale_win32.h:91:7: note: definition of 'locale_t' is not complete until the closing '}' 91 | class locale_t { | ^ C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/__support/win32/locale_win32.h:199:53: error: unknown type name '_locale_t' 199 | inline _LIBCPP_HIDE_FROM_ABI int islower_l(int __c, _locale_t __loc) { return _islower_l((int)__c, __loc); } | ^ C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/__support/win32/locale_win32.h:201:53: error: unknown type name '_locale_t' 201 | inline _LIBCPP_HIDE_FROM_ABI int isupper_l(int __c, _locale_t __loc) { return _isupper_l((int)__c, __loc); } | ^ C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/__support/win32/locale_win32.h:233:95: error: unknown type name 'va_list' 233 | _LIBCPP_EXPORTED_FROM_ABI int vasprintf_l(char** __ret, locale_t __loc, const char* __format, va_list __ap); | ^ In file included from D:\TS_Master\TSMaster\Configuration\TOSUN\TSMaster\MiniProgram\Build\CCode7142\CCode7142Extern.cpp:7: In file included from C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/vector:325: In file included from C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/__format/formatter_bool.h:20: In file included from C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/__format/formatter_integral.h:35: C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/locale:719:68: error: use of undeclared identifier '_strtoi64_l' 719 | long long __ll = strtoll_l(__a, &__p2, __base, _LIBCPP_GET_C_LOCALE); | ^ C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/__support/win32/locale_win32.h:189:19: note: expanded from macro 'strtoll_l' 189 | #define strtoll_l _strtoi64_l | ^ In file included from D:\TS_Master\TSMaster\Configuration\TOSUN\TSMaster\MiniProgram\Build\CCode7142\CCode7142Extern.cpp:7: In file included from C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/vector:325: In file included from C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/__format/formatter_bool.h:20: In file included from C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/__format/formatter_integral.h:35: C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/locale:751:68: error: use of undeclared identifier '_strtoui64_l' 751 | unsigned long long __ll = strtoull_l(__a, &__p2, __base, _LIBCPP_GET_C_LOCALE); | ^ C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/__support/win32/locale_win32.h:190:20: note: expanded from macro 'strtoull_l' 190 | #define strtoull_l _strtoui64_l | ^ In file included from D:\TS_Master\TSMaster\Configuration\TOSUN\TSMaster\MiniProgram\Build\CCode7142\CCode7142Extern.cpp:7: In file included from C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/vector:325: In file included from C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/__format/formatter_bool.h:20: In file included from C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/__format/formatter_integral.h:35: C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/locale:781:10: error: use of undeclared identifier '_strtod_l' 781 | return strtod_l(__a, __p2, _LIBCPP_GET_C_LOCALE); | ^ C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/__support/win32/locale_win32.h:191:18: note: expanded from macro 'strtod_l' 191 | #define strtod_l _strtod_l | ^ In file included from D:\TS_Master\TSMaster\Configuration\TOSUN\TSMaster\MiniProgram\Build\CCode7142\CCode7142Extern.cpp:7: In file included from C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/vector:325: In file included from C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/__format/formatter_bool.h:20: In file included from C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/__format/formatter_integral.h:35: C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/locale:1023:7: error: use of undeclared identifier '_sscanf_l' 1023 | if (__libcpp_sscanf_l(__buf.c_str(), _LIBCPP_GET_C_LOCALE, "%p", &__v) != 1) | ^ C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/__locale_dir/locale_base_api/bsd_locale_defaults.h:34:32: note: expanded from macro '__libcpp_sscanf_l' 34 | #define __libcpp_sscanf_l(...) sscanf_l(__VA_ARGS__) | ^ C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/__support/win32/locale_win32.h:227:38: note: expanded from macro 'sscanf_l' 227 | #define sscanf_l(__s, __l, __f, ...) _sscanf_l(__s, __f, __l, __VA_ARGS__) | ^ In file included from D:\TS_Master\TSMaster\Configuration\TOSUN\TSMaster\MiniProgram\Build\CCode7142\CCode7142Extern.cpp:7: In file included from C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/vector:325: In file included from C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/__format/formatter_bool.h:20: In file included from C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/__format/formatter_integral.h:35: C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/locale:1106:12: error: use of undeclared identifier '_isxdigit_l'; did you mean 'isxdigit'? 1106 | if (!isxdigit_l(*__ns, _LIBCPP_GET_C_LOCALE)) | ^ C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/__support/win32/locale_win32.h:204:20: note: expanded from macro 'isxdigit_l' 204 | #define isxdigit_l _isxdigit_l | ^ C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/cctype:122:9: note: 'isxdigit' declared here 122 | using ::isxdigit _LIBCPP_USING_IF_EXISTS; | ^ In file included from D:\TS_Master\TSMaster\Configuration\TOSUN\TSMaster\MiniProgram\Build\CCode7142\CCode7142Extern.cpp:7: In file included from C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/vector:325: In file included from C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/__format/formatter_bool.h:20: In file included from C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/__format/formatter_integral.h:35: C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/locale:1106:12: error: too many arguments to function call, expected 1, have 2; did you mean '::std::isxdigit'? 1106 | if (!isxdigit_l(*__ns, _LIBCPP_GET_C_LOCALE)) | ^~~~~~~~~~ C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/__support/win32/locale_win32.h:204:20: note: expanded from macro 'isxdigit_l' 204 | #define isxdigit_l _isxdigit_l | ^~~~~~~~~~~ C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/cctype:122:9: note: '::std::isxdigit' declared here 122 | using ::isxdigit _LIBCPP_USING_IF_EXISTS; | ^ In file included from D:\TS_Master\TSMaster\Configuration\TOSUN\TSMaster\MiniProgram\Build\CCode7142\CCode7142Extern.cpp:7: In file included from C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/vector:325: In file included from C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/__format/formatter_bool.h:20: In file included from C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/__format/formatter_integral.h:35: C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/locale:1110:12: error: use of undeclared identifier '_isdigit_l'; did you mean 'isdigit'? 1110 | if (!isdigit_l(*__ns, _LIBCPP_GET_C_LOCALE)) | ^ C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/__support/win32/locale_win32.h:203:19: note: expanded from macro 'isdigit_l' 203 | #define isdigit_l _isdigit_l | ^ C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/cctype:115:9: note: 'isdigit' declared here 115 | using ::isdigit _LIBCPP_USING_IF_EXISTS; | ^ In file included from D:\TS_Master\TSMaster\Configuration\TOSUN\TSMaster\MiniProgram\Build\CCode7142\CCode7142Extern.cpp:7: In file included from C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/vector:325: In file included from C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/__format/formatter_bool.h:20: In file included from C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/__format/formatter_integral.h:35: C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/locale:1110:12: error: too many arguments to function call, expected 1, have 2; did you mean '::std::isdigit'? 1110 | if (!isdigit_l(*__ns, _LIBCPP_GET_C_LOCALE)) | ^~~~~~~~~ C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/__support/win32/locale_win32.h:203:19: note: expanded from macro 'isdigit_l' 203 | #define isdigit_l _isdigit_l | ^~~~~~~~~~ C:\Program Files (x86)\TOSUN\TSMaster\Data\compilers\llvm_mingw_x86\bin/../include/c++/v1/cctype:115:9: note: '::std::isdigit' declared here 115 | using ::isdigit _LIBCPP_USING_IF_EXISTS; | ^ D:\TS_Master\TSMaster\Configuration\TOSUN\TSMaster\MiniProgram\Build\CCode7142\CCode7142Extern.cpp:67:17: error: use of undeclared identifier 'vsnprintf_s' 67 | while ((ret = vsnprintf_s(&buf[0], buf.size(), buf.size(), fmt, ap)) == -1) { | ^ D:\TS_Master\TSMaster\Configuration\TOSUN\TSMaster\MiniProgram\Build\CCode7142\CCode7142Extern.cpp:87:17: error: use of undeclared identifier 'vsnprintf_s' 87 | while ((ret = vsnprintf_s(&buf[0], buf.size(), buf.size(), fmt, ap)) == -1) { | ^ D:\TS_Master\TSMaster\Configuration\TOSUN\TSMaster\MiniProgram\Build\CCode7142\CCode7142Extern.cpp:104:110: error: format specifies type 'unsigned int' but the argument has type 's32' (aka 'long') [-Werror,-Wformat] 104 | sprintf(s, "%s %d %03X Tx d %d [%02X %02X %02X %02X %02X %02X %02X %02X]", ADesc, ACAN->FIdxChn, ACAN->FIdentifier, ACAN->FDLC, ACAN->FData[0], ACAN->FData[1], ACAN->FData[2], ACAN->FData[3], ACAN->FData[4], ACAN->FData[5], ACAN->FData[6], ACAN->FData[7]); | ~~~~ ^~~~~~~~~~~~~~~~~ | %03lX D:\TS_Master\TSMaster\Configuration\TOSUN\TSMaster\MiniProgram\Build\CCode7142\CCode7142Extern.cpp:106:68: error: format specifies type 'unsigned int' but the argument has type 's32' (aka 'long') [-Werror,-Wformat] 106 | sprintf(s, "%s %d %03X Tx r %d", ADesc, ACAN->FIdxChn, ACAN->FIdentifier, ACAN->FDLC); | ~~~~ ^~~~~~~~~~~~~~~~~ | %03lX fatal error: too many errors emitted, stopping now [-ferror-limit=] 20 errors generated.
09-26
#ifndef H_6B9572DA_A64B_49E6_B234_051480991C89 #define H_6B9572DA_A64B_49E6_B234_051480991C89 #ifndef __cplusplus # error "It's not going to compile without a C++ compiler..." #endif #if defined(BACKWARD_CXX11) #elif defined(BACKWARD_CXX98) #else # if __cplusplus >= 201103L # define BACKWARD_CXX11 # define BACKWARD_ATLEAST_CXX11 # define BACKWARD_ATLEAST_CXX98 # else # define BACKWARD_CXX98 # define BACKWARD_ATLEAST_CXX98 # endif #endif // You can define one of the following (or leave it to the auto-detection): // // #define BACKWARD_SYSTEM_LINUX // - specialization for linux // // #define BACKWARD_SYSTEM_UNKNOWN // - placebo implementation, does nothing. // #if defined(BACKWARD_SYSTEM_LINUX) #elif defined(BACKWARD_SYSTEM_UNKNOWN) #else # if defined(__linux) # define BACKWARD_SYSTEM_LINUX # else # define BACKWARD_SYSTEM_UNKNOWN # endif #endif #include <fstream> #include <iostream> #include <algorithm> #include <cstdlib> #include <cstdio> #include <cstring> #include <cctype> #include <string> #include <new> #include <iomanip> #include <vector> #if defined(BACKWARD_SYSTEM_LINUX) // On linux, backtrace can back-trace or "walk" the stack using the following // libraries: // // #define BACKWARD_HAS_UNWIND 1 // - unwind comes from libgcc, but I saw an equivalent inside clang itself. // - with unwind, the stacktrace is as accurate as it can possibly be, since // this is used by the C++ runtine in gcc/clang for stack unwinding on // exception. // - normally libgcc is already linked to your program by default. // // #define BACKWARD_HAS_BACKTRACE == 1 // - backtrace seems to be a little bit more portable than libunwind, but on // linux, it uses unwind anyway, but abstract away a tiny information that is // sadly really important in order to get perfectly accurate stack traces. // - backtrace is part of the (e)glib library. // // The default is: // #define BACKWARD_HAS_UNWIND == 1 // // Note that only one of the define should be set to 1 at a time. // # if BACKWARD_HAS_UNWIND == 1 # elif BACKWARD_HAS_BACKTRACE == 1 # else # undef BACKWARD_HAS_UNWIND # define BACKWARD_HAS_UNWIND 1 # undef BACKWARD_HAS_BACKTRACE # define BACKWARD_HAS_BACKTRACE 0 # endif // On linux, backward can extract detailed information about a stack trace // using one of the following libraries: // // #define BACKWARD_HAS_DW 1 // - libdw gives you the most juicy details out of your stack traces: // - object filename // - function name // - source filename // - line and column numbers // - source code snippet (assuming the file is accessible) // - variables name and values (if not optimized out) // - You need to link with the lib "dw": // - apt-get install libdw-dev // - g++/clang++ -ldw ... // // #define BACKWARD_HAS_BFD 1 // - With libbfd, you get a fair amount of details: // - object filename // - function name // - source filename // - line numbers // - source code snippet (assuming the file is accessible) // - You need to link with the lib "bfd": // - apt-get install binutils-dev // - g++/clang++ -lbfd ... // // #define BACKWARD_HAS_BACKTRACE_SYMBOL 1 // - backtrace provides minimal details for a stack trace: // - object filename // - function name // - backtrace is part of the (e)glib library. // // The default is: // #define BACKWARD_HAS_BACKTRACE_SYMBOL == 1 // // Note that only one of the define should be set to 1 at a time. // # if BACKWARD_HAS_DW == 1 # elif BACKWARD_HAS_BFD == 1 # elif BACKWARD_HAS_BACKTRACE_SYMBOL == 1 # else # undef BACKWARD_HAS_DW # define BACKWARD_HAS_DW 0 # undef BACKWARD_HAS_BFD # define BACKWARD_HAS_BFD 0 # undef BACKWARD_HAS_BACKTRACE_SYMBOL # define BACKWARD_HAS_BACKTRACE_SYMBOL 1 # endif # if BACKWARD_HAS_UNWIND == 1 # include <unwind.h> // while gcc's unwind.h defines something like that: // extern _Unwind_Ptr _Unwind_GetIP (struct _Unwind_Context *); // extern _Unwind_Ptr _Unwind_GetIPInfo (struct _Unwind_Context *, int *); // // clang's unwind.h defines something like this: // uintptr_t _Unwind_GetIP(struct _Unwind_Context* __context); // // Even if the _Unwind_GetIPInfo can be linked to, it is not declared, worse we // cannot just redeclare it because clang's unwind.h doesn't define _Unwind_Ptr // anyway. // // Luckily we can play on the fact that the guard macros have a different name: #ifdef __CLANG_UNWIND_H // In fact, this function still comes from libgcc (on my different linux boxes, // clang links against libgcc). # include <inttypes.h> extern "C" uintptr_t _Unwind_GetIPInfo(_Unwind_Context*, int*); #endif # endif # include <cxxabi.h> # include <fcntl.h> # include <link.h> # include <sys/stat.h> # include <syscall.h> # include <unistd.h> # include <signal.h> # if BACKWARD_HAS_BFD == 1 // NOTE: defining PACKAGE{,_VERSION} is required before including // bfd.h on some platforms, see also: // https://sourceware.org/bugzilla/show_bug.cgi?id=14243 # ifndef PACKAGE # define PACKAGE # endif # ifndef PACKAGE_VERSION # define PACKAGE_VERSION # endif # include <bfd.h> # ifndef _GNU_SOURCE # define _GNU_SOURCE # include <dlfcn.h> # undef _GNU_SOURCE # else # include <dlfcn.h> # endif # endif # if BACKWARD_HAS_DW == 1 # include <elfutils/libdw.h> # include <elfutils/libdwfl.h> # include <dwarf.h> # endif # if (BACKWARD_HAS_BACKTRACE == 1) || (BACKWARD_HAS_BACKTRACE_SYMBOL == 1) // then we shall rely on backtrace # include <execinfo.h> # endif #endif // defined(BACKWARD_SYSTEM_LINUX) #ifdef BACKWARD_ATLEAST_CXX11 # include <unordered_map> # include <utility> // for std::swap namespace backward { namespace details { template <typename K, typename V> struct hashtable { typedef std::unordered_map<K, V> type; }; using std::move; } // namespace details } // namespace backward #else // NOT BACKWARD_ATLEAST_CXX11 # include <map> namespace backward { namespace details { template <typename K, typename V> struct hashtable { typedef std::map<K, V> type; }; template <typename T> const T& move(const T& v) { return v; } template <typename T> T& move(T& v) { return v; } } // namespace details } // namespace backward #endif // BACKWARD_ATLEAST_CXX11 namespace backward { namespace system_tag { struct linux_tag; // seems that I cannot call that "linux" because the name // is already defined... so I am adding _tag everywhere. struct unknown_tag; #if defined(BACKWARD_SYSTEM_LINUX) typedef linux_tag current_tag; #elif defined(BACKWARD_SYSTEM_UNKNOWN) typedef unknown_tag current_tag; #else # error "May I please get my system defines?" #endif } // namespace system_tag 注释上述代码
最新发布
09-29
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值