The GNU C Library: Feature Selection

by Humberto Mitchson.

Share
|
Homepage | Submit your article | Contact | TOS
More articles on linux  

You are here: Categories » Computers and technology » Linux

In glibc, there are a set of feature selection macros that are used to select which standards you wish glibc to comply with. Standards sometimes conflict, and so glibc allows you to select exactly which set of standards (formal, de jure, and informal, de facto) with which to comply, fully or partially. These macros are technically called feature test macros.

You need to be aware of these macros because the default set of macros defined does not provide all the functionality of glibc. A few mechanisms are not available with the default feature set selected; we document the required feature macros to use each of these mechanisms.

The feature test macros are designed to specify with what standards (de jure or de facto), and in some cases precisely which versions of those standards, glibc should comply. This compliance often includes not defining functions and macros beyond what is specified by a standard for header files that are themselves defined by that standard. That means that an application written to conform with a standard can define its own functions and macros without conflicting with extensions not defined by that standard.

The feature test macros do not guarantee that your application is fully compatible with the set of standards specified by the set of macros you define. Setting the feature test macros may find some use of nonportable extensions, but it will not show, for example, use of header files that are entirely unspecified by the standard.

The macros are defined in the system header file feature.h, which you should not include directly. Instead, all other header files that might be affected by the contents of feature.h include it.

The default set of feature macros if none are defined is _SVID_SOURCE=1,_BSD_SOURCE=1,_POSIX_SOURCE=1, and _POSIX_C_SOURCE=199506L. Each option is described in more detail below, but this essentially translates into "support the capabilities of the 1995 POSIX standard, all standard System V features, and all BSD features that do not conflict with System V features." This default set of feature macros suffices for most programs.

When you give gcc the -ansi option, it automatically defines the internal __STRICT_ANSI__ macro, which turns off all the default feature macros.

With the exception of the __STRICT_ANSI__ macro, which is special (and which should be set only by the compiler in the context of the -ansi command line option), these feature macros are cumulative; you can define any combination of them. The exact definition of _BSD_SOURCE changes depending on which other feature macros are set (as documented below); the rest are purely cumulative.

Some of the feature test macros are defined by various versions of POSIX or other standards, some are common in the industry, and others are strictly limited to glibc.

_POSIX_SOURCE If this macro is defined, all the interfaces defined as part of the original POSIX.1 specification are made available.
This macro was defined by the original POSIX.1-1990 standard.
_POSIX_C_SOURCE This macro supersedes _POSIX_SOURCE. If it is set to 1, it is equivalent to _POSIX_SOURCE. If it is >=2, then it also includes C interfaces defined by POSIX.2, including regular expressions. If it is >=199309L, then it also includes additional C interfaces defined in the 1993 revision of POSIX, particularly including the soft real-time functionality; if it is >=199506L (the default), it also includes additional C interfaces defined in the 1995 revision of POSIX, particularly including POSIX threads. This macro was defined by versions of POSIX released after 1990 in order to differentiate support for various versions of the POSIX (and now also Single Unix) standards. It is largely superseded by _XOPEN_SOURCE.
_XOPEN_SOURCE The _XOPEN_SOURCE macro is defined by the XSI portion of the Single Unix Standard, and defines a logical superset of the interfaces included by _POSIX_C_SOURCE. It was also defined by XPG. If it is defined at all, base-level conformance with XPG4 (Unix95) is included. If it is defined as 500, then base-level conformance with XPG5 (Unix98, SuS version 2) is included. If it is defined as 600, base-level conformance with IEEE Std 1003.1-2003 (the combined POSIX and SuS document) is included.
_ISOC99_SOURCE This feature test macro exports the interfaces defined by the new ISO/IEC C99 standard.
_SVID_SOURCE This feature test macro makes functionality specified by the System V Interface Definition (SVID) available. This does not imply that glibc provides a complete implementation of the SVID standard; it merely exposes the SVID-specified functionality that exists in glibc.
_BSD_SOURCE BSD features can conflict with other features, and the conflicts are always resolved in favor of System Vor standard-compliant behavior if any POSIX, X/Open, or System V feature macro is defined or implied—so the only feature macro that allows BSD behavior to be asserted is _ISOC99_SOURCE. (The exact definition of this feature test macro has changed from time to time, and may change again, since it is not specified by any standard.)
_GNU_SOURCE _GNU_SOURCE turns on everything possible, favoring System V interfaces to BSD interfaces in cases of conflict. It also adds some GNU- and Linux-specific interfaces, such as file leases.


When the standard set of feature test macros will not suffice, the most commonly useful feature macros to define are _GNU_SOURCE (turn everything on—the easiest solution), _XOPEN_SOURCE=600 (most things you are likely to care about, a subset of _GNU_SOURCE), or _ISOC99_SOURCE (use features from the most recent C standard, a subset of _XOPEN_SOURCE=600).

Leave a comment or ask a question
Total comments: 0

Linux Disclaimer

  • The e-articles directory is not responsible for any and all copyright infringements by writers and authors. If you suspect the information contained by this page for any copyright infringements, please contact us to investigate the issue
History of Kubuntu - When Ubuntu was first being discussed there were rumors that it would be only based on GNOME, and KDE would be left out. Jonathan Riddell, a KDE developer, posted an article on his (more...)
Installing Kubuntu - Installing Kubuntu is just like installing Ubuntu. It is pretty much a snap. Let's start with where you find it. Where to Find Kubuntu Kubuntu is available a (more...)
Root iNode Corruption Cause Data Loss in Linux - Article contains information over root I node corruption failure causes data loss. Article also contains recovery solution for all kind of data loss in linux. In Linux and other Unix-like o (more...)
LINUX r Services - rlogind and rshd are the remote login and remote shell daemon. These so-called r services use TCP ports 513 and 514, respectively. The RLOGIN protocol is described in RFC 1282 and RSH in RFC. (more...)
Short History of Ubuntu - Born in April 2004, a history of Ubuntu may seem premature. However, the last years have been full ones for Ubuntu. With its explosive growth, it is difficult even for those involv (more...)
Free Open source Software and GNU Linux - Free Software and GNUIn a series of events that have almost become legend through constant repetition, Richard M. Stallman created the concept of "free software" in 1983. Stallman grew (more...)
Choose an Ubuntu Version - The developers behind Ubuntu have worked to make the software as easy and flexible to install as possible. They understand that people will be installing Ubuntu on different types of computers (more...)
Customize Ubuntu Look and Feel - Changing the Background To change the background of your desktop right-click it and select Change Desktop Background. Inside the dialog box that appears, choose yo (more...)
Configuring a Printer in Ubuntu - In the Linux world, configuring a printer has traditionally been a challenge. For years, newcomers to Linux have been repeatedly challenged and even bludgeoned with terms, commands, and phrases (more...)
Working with Windows from inside Ubuntu - Although the Linux platform offers an increasingly compelling platform for the desktop, there are sometimes situations when there is just no alternative application available. This is often the (more...)

 
free content
    Copyright © 2006 - 2012 e-articles.info.
The texts, articles and tutorials in the directory are property of their respective owners and authors.