public inbox for cygwin-developers@cygwin.com
 help / color / mirror / Atom feed
From: Jon TURNEY <jon.turney@dronecode.org.uk>
To: cygwin-developers@cygwin.com
Subject: Fwd: A small issue with _GNU_SOURCE
Date: Tue, 17 Feb 2015 18:25:00 -0000	[thread overview]
Message-ID: <54E38776.1030707@dronecode.org.uk> (raw)
In-Reply-To: <54E3808B.9040302@dronecode.org.uk>


Consider the following:

$ cat test.c
#include <string.h>
#include <stdlib.h>

int main()
{
  long long i = random();
  return ffsll(i);
}

ffsll() is a GNU extension and should be prototyped when _GNU_SOURCE is 
defined.

random() is in SUSv2 and requires _XOPEN_SOURCE=500

$ gcc test.c -Wall -ansi -D_XOPEN_SOURCE=700
test.c: In function ‘main’:
test.c:8:2: warning: implicit declaration of function ‘ffsll’

This is correct

$ gcc test.c -Wall -ansi -D_XOPEN_SOURCE=700 -D_GNU_SOURCE
test.c: In function ‘main’:
test.c:8:2: warning: implicit declaration of function ‘ffsll’

This looks like a problem with newlib's sys/cdefs.h.  _XOPEN_SOURCE 
causes _POSIX_C_SOURCE to be defined, which prevents _GNU_SOURCE from 
being considered.

$ gcc test.c -Wall -ansi -D_GNU_SOURCE
test.c: In function ‘main’:
test.c:7:2: warning: implicit declaration of function ‘random’

_GNU_SOURCE is supposed to imply some value of _XOPEN_SOURCE, but only 
actually turns on __XSI_VISIBLE.

The patch I wrote for cygwin's stdlib.h [1] explicitly checks 
_XOPEN_SOURCE.  Should this be a check for XSI_VISIBLE? or should 
cdefs.h also define _XOPEN_SOURCE (and all the other feature test macros 
that _GNU_SOURCE is defined to be equivalent to)?

[1] https://cygwin.com/ml/cygwin-patches/2013-q4/msg00004.html

       reply	other threads:[~2015-02-17 18:25 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <54E3808B.9040302@dronecode.org.uk>
2015-02-17 18:25 ` Jon TURNEY [this message]
2015-02-17 21:43   ` Corinna Vinschen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=54E38776.1030707@dronecode.org.uk \
    --to=jon.turney@dronecode.org.uk \
    --cc=cygwin-developers@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).