Understanding Standard Library (ctype.h) Compilation Errors

Asked 2 years ago, Updated 2 years ago, 125 views

We are developing an open source called ardupilot while modifying it.
An error occurred in the standard library during a recent g++ build.The error is as follows (environment is ubuntud):

Infile included from/usr/include/c++/5/bits/basic_ios.h:37:0,
             from /usr/include/c++/5/ios:44,
             from/usr/include/c++/5/ostream:38,
             from/usr/include/c++/5/iostream:39,
             from../../libraries/AP_IRLock/AP_IRLock_SITL.cpp:30:
/usr/include/c++/5/bits/locale_facets.h:2601:44:error:macro "isdigit" passed 2 arguments, but takes just 1
 isdigit(_CharT__c, const locale&__loc)
                                        ^
compilation terminated due to-Wfatal-errors.

Based on the content, two isdigit function arguments are specified in locale_facets.h, but only one isdigit function argument in ctype.h is requested.
In fact, we have verified that isidigit in /usr/include/c++/5/bits/locale_facets.h and isdigit in /usr/include/cttype.h are different.
I changed the g++ version to 4.7 but it didn't work.
By the way, the current version of g++ is 5.4.1.
I also installed g++ and gcc, but the result was no good.

Please help me.

linux c++ ubuntu gcc

2022-09-29 22:51

2 Answers

I think the source is C++, but /usr/include/cttype.h is a header file for C, so there is a discrepancy.
If you review the include line and call std::isdigit as defined in #include<locale>, you will be able to use isdigit with two arguments.

isdigit for ctype.h
isdigit

in std::locale

std::code sample using isdigit

//isdigit example(C++)
# include<iostream>//std::cout
# include <string>// std::string
# include<locale>//std::locale,std::isdigit
# include<sstream>//std::stringstream

int main()
{
  std::localeloc;
  std::string str = "1776ad";
  if(isdigit(str[0], loc))
  {
    int year;
    std::stringstream(str)>>year;
    std::cout<<"The year that followed"<<year<<"was"<<(year+1)<<.\n";
  }
  return 0;
}

reference:
Related Questions in English SO
c++-isspace macro conflicting with ispace function in locale_facets.h


2022-09-29 22:51


© 2024 OneMinuteCode. All rights reserved.