From owner-freebsd-standards@FreeBSD.ORG Thu Mar 18 15:55:43 2004 Return-Path: Delivered-To: freebsd-standards@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 0E73216A4CE for ; Thu, 18 Mar 2004 15:55:43 -0800 (PST) Received: from mailout2.pacific.net.au (mailout2.pacific.net.au [61.8.0.85]) by mx1.FreeBSD.org (Postfix) with ESMTP id 4EA2443D2D for ; Thu, 18 Mar 2004 15:55:42 -0800 (PST) (envelope-from bde@zeta.org.au) Received: from mailproxy2.pacific.net.au (mailproxy2.pacific.net.au [61.8.0.87])i2INtcnX016651; Fri, 19 Mar 2004 10:55:38 +1100 Received: from gamplex.bde.org (katana.zip.com.au [61.8.7.246]) i2INtaGi014860; Fri, 19 Mar 2004 10:55:37 +1100 Date: Fri, 19 Mar 2004 10:55:35 +1100 (EST) From: Bruce Evans X-X-Sender: bde@gamplex.bde.org To: Archie Cobbs In-Reply-To: <200403182233.i2IMXPuJ002724@arch20m.dellroad.org> Message-ID: <20040319102323.Q23424@gamplex.bde.org> References: <200403182233.i2IMXPuJ002724@arch20m.dellroad.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII cc: freebsd-standards@freebsd.org Subject: Re: _BSD_SOURCE vs. __BSD_VISIBLE X-BeenThere: freebsd-standards@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Standards compliance List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 18 Mar 2004 23:55:43 -0000 On Thu, 18 Mar 2004, Archie Cobbs wrote: > All I'm trying to do is write some portable code :-) > > Here "portable" simply means that it compiles on both FreeBSD and Linux. > In order to get the various functions I need I have to set a bunch of flags. > > On Linux, these flags do the trick (taken from configure.in): > > AC_DEFINE(_XOPEN_SOURCE, 600, XOpen functions) > AC_DEFINE(_GNU_SOURCE, 1, GNU functions) > AC_DEFINE(_BSD_SOURCE, 1, BSD functions) > AC_DEFINE(_ISOC99_SOURCE, 1, ISO C99 functions) > AC_DEFINE(_POSIX_VERSION, 200112, POSIX version) > AC_DEFINE(_POSIX_C_SOURCE, 200112, POSIX functions) Using these tends to restrict potability. Defining _POSIX_C_SOURCE restricts visibility to the specified version of POSIX, except some settings of _XOPEN_SOURCE have precedence and restrict visibility to the specified version of XSI. Defining the others gives undefined behaviour; the actual behaviour is to have no effect under FreeBSD, but apparently these identifiers are part of the Linux defacto standard so they do something there. FreeBSD has _C99_SOURCE, which may work like _ISOC99_SOURCE, and _ANSI_SOURCE which restricts to C90, and _POSIX_SOURCE which restricts to the POSIX.1-1990. > On FreeBSD, _BSD_SOURCE is not recognized, but _POSIX_C_SOURCE is and > it actually causes the BSD functions to be hidden. So I have to manually > add __BSD_VISIBLE to get them on FreeBSD. The only way to get all (Free)BSD functions under FreeBSD is to not define any identifiers that restrict visibility. > Q1: Why does Linux require _BSD_SOURCE but FreeBSD requires __BSD_VISIBLE? Linux apparently requires _BSD_SOURCE to give BSD extensions. This is a bug in Linux. The BSD extensions are better of course :-), and feature tests macros should generally restrict, not enable extensions. I think Linux does this because some BSD extensions are incompatible. FreeBSD doesn't require __BSD_VISIBLE. On the contrary, __BSD_VISIBLE is an implementation detail, and setting it in applications gives undefined behaviour. > Q2: Is there some standard for these flags documented somewhere? _POSIX_C_SOURCE and _XOPEN_SOURCE are documented in the POSIX.1-2001 standard. So is _POSIX_VERSION, but it is quite different (the system defines it). The others are nonstandard. > Q3: What is the right and portable set of flags to use? There is none. For FreeBSD, you probably need a null set of flags. For Linux, this is the wrong list to ask on :-). Bruce