PDA

View Full Version : man 7 feature_test_macros --> question



tindala
03-03-2014, 07:27 AM
i cam across this:
man 7 feature_test_macros
in its info page i found the following;:
acct(): _BSD_SOURCE || (_XOPEN_SOURCE && _XOPEN_SOURCE < 500)

i have not understood why it has to be instead:


acct(): _BSD_SOURCE || ( _XOPEN_SOURCE < 500)

thank you in advance for the answer

tindala
03-03-2014, 07:31 AM
furthermore, for the feature test macro:
acct(): _BSD_SOURCE || (_XOPEN_SOURCE && _XOPEN_SOURCE < 500)
i need to write the following macro definitions:
#define _BSD_SOURCE
#define _XOPEN_SOURCE /* or any value < 500 */

but for
gethostname():
Since glibc 2.12: _BSD_SOURCE || _XOPEN_SOURCE >= 500

what macro definitions i have to write?

tindala
03-03-2014, 07:32 AM
and what value is this 500 ?

tindala
03-03-2014, 07:42 AM
how about also this one:
getaddrinfo(), freeaddrinfo(), gai_strerror():
_POSIX_C_SOURCE >= 1 || _XOPEN_SOURCE || _POSIX_SOURCE
what macros do i need to use? how even i write the test _POSIX_C_SOURCE >= 1 ?

tabstop
03-03-2014, 08:38 AM
If you were looking at the man 7 page for feature test macros, why didn't you read the bit at the top about which macros should be defined when (and what their value should be, and what "500" means, and all the rest)?

As to the first question, if _XOPEN_SOURCE is not defined, then it will be treated as 0 when compared to a number, which would unexpectedly make that condition true. Thus you check that it is defined, and then that it has a value less than 500.

tindala
03-03-2014, 10:51 AM
ok,
then for this feature test macro:
acct(): _BSD_SOURCE || (_XOPEN_SOURCE && _XOPEN_SOURCE < 500)
i have answered the following:

"
As to the first question, if _XOPEN_SOURCE is not defined, then it will be treated as 0 when compared to a number, which would unexpectedly make that condition true. Thus you check that it is defined, and then that it has a value less than 500.
"
then it will be treated as 0 when compared to a number , the test is done in this condition: _XOPEN_SOURCE < 500 , then how do i test that it has a value less than 500 ?

tindala
03-03-2014, 10:56 AM
and for this test macro:
this one:
getaddrinfo(), freeaddrinfo(), gai_strerror():
_POSIX_C_SOURCE >= 1 || _XOPEN_SOURCE || _POSIX_SOURCE

the definitions are written for example in the following way?:::::
#define _POSIX_C_SOURCE 2
#define XOPEN_SOURCE
#define _POSIX_SOURCE

tabstop
03-03-2014, 11:27 AM
ok,
then for this feature test macro:
acct(): _BSD_SOURCE || (_XOPEN_SOURCE && _XOPEN_SOURCE < 500)
i have answered the following:

"
As to the first question, if _XOPEN_SOURCE is not defined, then it will be treated as 0 when compared to a number, which would unexpectedly make that condition true. Thus you check that it is defined, and then that it has a value less than 500.
"
then it will be treated as 0 when compared to a number , the test is done in this condition: _XOPEN_SOURCE < 500 , then how do i test that it has a value less than 500 ?
You've got the test for testing that it has a value less than 500 already written in your post, so I don't know why you're asking.

Also, unless you are planning to be writing the header files yourself, you don't do the test. Your job is to define the appropriate macro that matches what you want reality to be, and that's all you do. For example, if you want the compiler to act like it's System V, then you #define _SVID_SOURCE. If you want the compiler to match the C11 standard, you #define _ISOC11_SOURCE.