[Mesa-dev] Mesa (master): glsl: Add using statements for standard library functions.

Vinson Lee vlee at vmware.com
Fri Feb 4 11:16:55 PST 2011

> -----Original Message-----
> On 02/03/2011 10:36 PM, Jose Fonseca wrote:
> > This is very odd behavior from Sun's compiler -- unless we include
> > cstdio, printf should be available, not std::printf.
> I think we might use cstdio in some places.  I find it odd that Sun's
> compiler differs from GCC, Visual Studio, ICC, and clang.  I'm tempted
> to say they're doing it wrong.  Is there perhaps a command line option
> for Sun's compiler that could change this behavior?  Not only is having
> to add extra using statements ugly, but I can guarantee it will be
> missed in the future.
> Maybe the better answer is to not use cstdio and friends at all.

GNU doesn't guarantee that C standard library symbols from C++-style headers are in the global namespace, although in practice they always are.

Here's the link to the GNU manual.


The standard specifies that if one includes the C-style header (<math.h> in this case), the symbols will be available in the global namespace and perhaps in namespace std:: (but this is no longer a firm requirement.) On the other hand, including the C++-style header (<cmath>) guarantees that the entities will be found in namespace std and perhaps in the global namespace.

Usage of C++-style headers is recommended, as then C-linkage names can be disambiguated by explicit qualification, such as by std::abort. In addition, the C++-style headers can use function overloading to provide a simpler interface to certain families of C-functions. For instance in <cmath>, the function std::sin has overloads for all the builtin floating-point types. This means that std::sin can be used uniformly, instead of a combination of std::sinf, std::sin, and std::sinl.

More information about the mesa-dev mailing list