delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2010/01/19/23:06:44

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=-2.0 required=5.0 tests=AWL,BAYES_00,SPF_SOFTFAIL
X-Spam-Check-By: sourceware.org
Message-ID: <4B568160.3070300@byu.net>
Date: Tue, 19 Jan 2010 21:06:56 -0700
From: Eric Blake <ebb9 AT byu DOT net>
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.23) Gecko/20090812 Thunderbird/2.0.0.23 Mnenhy/0.7.6.666
MIME-Version: 1.0
To: cygwin AT cygwin DOT com
Subject: Re: g++: -ansi flag makes snprintf() unavailable?
References: <4B56745F DOT 9070903 AT monai DOT ca>
In-Reply-To: <4B56745F.9070903@monai.ca>
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

--------------enig5EF3E5AB79DBC29A5A6FA361
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

According to Steven Monai on 1/19/2010 8:11 PM:
> I compile and run this program as follows:
>=20
> $ g++ -ansi -o mytest mytest.cc && ./mytest

Using -ansi generally says that you want the headers to expose ONLY the
interfaces mentioned in the C89 standard.  But C89 did not describe
snprintf, hence your compilation failure.  Filtering declarations based on
various standards is something that glibc does better than newlib; this is
a known weakness in newlib, and patches are thoughtfully considered.  And
c++ has different rules than C89 about what is provided by default, so it
is entirely possible that you found a bug that should be reported to the
newlib list.

In the meantime, either don't use snprintf without declaring it by hand,
or else don't use -ansi, since they are obviously not compatible in the
current state of the headers.

>=20
> Furthermore, when I replace the cout line with a printf(), the compiler
> never complains about printf(), regardless of the presence or absence of
> the -ansi flag. I find that puzzling, since I'd expect printf() and
> snprintf(), being related functions, to be affected in the same way by
> the compilation flags.

But C89 did describe printf.  For a similar example, consider dprintf,
which is also in the *printf family.  It is not part of C99, but is part
of POSIX 2008.  We've already established that newlib's headers don't do
the best of filtering, but on glibc systems, in order to get <stdio.h> to
expose dprintf, you have to pre-define either _GNU_SOURCE or
_POSIX_C_SOURCE prior to including the header, to tell the compiler that
you intend to use a standard that provides more interfaces than stock C89.

--=20
Don't work too hard, make some time for fun as well!

Eric Blake             ebb9 AT byu DOT net


--------------enig5EF3E5AB79DBC29A5A6FA361
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="signature.asc"

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAktWgWMACgkQ84KuGfSFAYBwhQCgklsBl+STECQXnhg2dRriBnV0
ZH8AnRXUb9pin5bCyWoSc/XCHRmQMy87
=CUxl
-----END PGP SIGNATURE-----

--------------enig5EF3E5AB79DBC29A5A6FA361--

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019