From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,38159b1b5557a2e7 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2004-01-26 15:44:29 PST Path: archiver1.google.com!news2.google.com!news.maxwell.syr.edu!eusc.inter.net!cs.tu-berlin.de!uni-duisburg.de!not-for-mail From: Georg Bauhaus Newsgroups: comp.lang.ada Subject: Re: Standard Ada Preprocessor Date: Mon, 26 Jan 2004 23:44:28 +0000 (UTC) Organization: GMUGHDU Message-ID: References: <400D2150.6000705@noplace.com> <400E72F9.8060501@noplace.com> <100upo7ln5e3k59@corp.supernews.com> <400FC8E8.2040100@noplace.com> <_JSdna166JuxFo3dRVn-hg@comcast.com> <401115B7.5020205@noplace.com> NNTP-Posting-Host: l1-hrz.uni-duisburg.de X-Trace: a1-hrz.uni-duisburg.de 1075160668 11927 134.91.1.34 (26 Jan 2004 23:44:28 GMT) X-Complaints-To: usenet@news.uni-duisburg.de NNTP-Posting-Date: Mon, 26 Jan 2004 23:44:28 +0000 (UTC) User-Agent: tin/1.5.8-20010221 ("Blue Water") (UNIX) (HP-UX/B.11.00 (9000/800)) Xref: archiver1.google.com comp.lang.ada:4849 Date: 2004-01-26T23:44:28+00:00 List-Id: Warren W. Gay VE3WWG wrote: : For example, you'd pretty much have to have a different package : for every POSIX-like environment, because of changes like what : was included in the stat(2) structure (and others). Worse, you'd : have to matrix it out to the various releases of Linux, FreeBSD, : NetBSD, OpenBSD, Solaris, IRIX, HPUX etc. You cannot hope to : accommodate all of these differences by package names. Not throwing in everything, (though that adds combinations no matter which method is chosen to deal with the variety), the following works for me (and also in more complex arrangements). I will have to make exactly two changes if I want to switch the OS/POSIX combination: with OS; -- see next procedure run is use OS.BSD; sample_file: constant := -321; -- just any unlikely file descriptor, don't create havoc -- We need C.int comparisons for function returns, so: use type int; begin -- bad style and all sorts of things... if C_MINUS_1 = lockf(sample_file, F_LOCK, 8192) then raise Program_Error; end if; end run; with Systems.BSD_x86; -- with other Systems as well... package OS is package BSD renames Systems.BSD_x86.FantasyBSD.Non_Standard_POSIX; -- package Linux renames ...; -- package SUNOS renames ...; -- package MacOS renames ...; end OS; package Systems is end Systems; with Interfaces.C; use Interfaces; package Systems.BSD_x86 is -- POSIX items for all flavours of BSD for x86. -- As there are allegedly both Standard POSIX items and non-standard -- ones on some (possibly older) systems, see Warren W. Gay's posting, -- there is a Non_Standard_POSIX and a Standard_POSIX package in -- each BSD variant package. -- ---------------- -- FantasyBSD -- ---------------- package FantasyBSD is package Non_Standard_POSIX is use type C.int; C_MINUS_1: constant C.int := -1; -- indicating a failing function F_LOCK: constant C.int := 3_4829; -- surprising value subtype off_t is C.long; subtype int is C.int; function lockf (file_descriptor: int; function_number: int; bytes: off_t) return int; pragma import(C, lockf); end Non_Standard_POSIX; package Standard_POSIX is -- rename needed functions from ISO Ada Bindings end Standard_POSIX; end FantasyBSD; -- ---------------- -- OpenBSD -- ---------------- package OpenBSD is end OpenBSD; -- ---------------- -- FreeBSD -- ---------------- package FreeBSD is end FreeBSD; -- ... end Systems.BSD_x86; georg@strudel:~/rsrc/Ada/wg$ gnatmake run gcc -c run.adb gcc -c os.ads gcc -c systems.ads gcc -c systems-bsd_x86.ads gnatbind -x run.ali gnatlink run.ali georg@strudel:~/rsrc/Ada/wg$ ./run raised PROGRAM_ERROR : run.adb:15 explicit raise georg@strudel:~/rsrc/Ada/wg$ Most outstanding bug: the program has been compiled on Linux strudel 2.4.18 #1 Fri May 2 17:22:29 CEST 2003 i686 unknown ;-) : I get frustrated with the short sightedness of the "not invented : here syndrome". But maybe, that is just me. ;-) Hm. Plan 9's C enviroment does well without #ifdefs, even though it has to provide this environment for different architectures. This is reported to be confusing for those who have unfortunately been told to use #if defined __THIS_HEADER__ in header files, as a replacement for a design that keeps things separate so multiple inclusion does not occur.