ARM Technical Support Knowledge Articles

Why do the "cname" headers (e.g., cmath) not include the "name.h" headers (e.g., math.h) within the global namespace?

Applies to: DS-5, RealView Development Suite (RVDS)

Scenario

The C++ standard (section "Library-wide requirements") specifies that the declarations in the cname headers or the corresponding name.h header are within namespace scope of the namespace "std". It is unspecified whether these names are first declared within the global namespace scope and are then injected into namespace "std" by explicit using-declarations (e.g., using namespace std;).

For example, compiling the following code that includes cmath with armcc --cpp:

#include <cmath>
double foo(double num)
{
  return ceil(num);
}


... will generate the following error message:

"test.cpp", line 7: Error:  #20: identifier "ceil" is undefined
    return ceil(num);
           ^
test.cpp: 0 warnings, 1 error

This error occurs because cmath does not include math.h functions in the global namespace. Other compilers might implement this differently and compile the above example without giving an error.

Answer

One workaround is to modify your source code so that it references the cname functions under the std:: namespace. For example:

#include <cmath>
using namespace std;
double foo(double num)
{
  return ceil(num);
}


Alternatively, if modifying source code is undesirable, you can use the compiler option --using_std.

Rate this article

[Bad]
|
|
[Good]
Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential