From ripley at stats.ox.ac.uk  Sat Sep 26 11:40:11 2009
From: ripley at stats.ox.ac.uk (Prof Brian Ripley)
Date: Sat, 26 Sep 2009 10:40:11 +0100 (BST)
Subject: [Rd] Compatibility of external C code across platforms
In-Reply-To: <E67251526203864DABCB7237DAC8EB2D759B1D232D@MAIL2.registry.otago.ac.nz>
References: <E67251526203864DABCB7237DAC8EB2D759B1D232D@MAIL2.registry.otago.ac.nz>
Message-ID: <alpine.LFD.2.00.0909261021460.14015@gannet.stats.ox.ac.uk>

On Sat, 26 Sep 2009, Murray Efford wrote:

> A package I have written makes considerable use of external C code. 
> There appear to be no problems building a Windows binary with the 
> GNU C compiler, but now I would like to make the package available 
> for other platforms.  A stringent check of the code with the gcc 
> options '-Wall -pedantic' flags many nested functions and 
> variable-length arrays that are not allowed in ISO C.  Is it 
> essential that distributed C source code for R packages conforms to 
> ISO C in this respect?  I'm working in Windows XP with R2.9.2 and 
> Rtools 2.9.

Yes, it is essential.  R does not assume gcc, and it does not even 
assume gcc 4.x (and people are still using gcc 3.x on some platforms, 
e.g. the sunfreeware R builds).  This is why we publish test result on 
CRAN for a completely different compiler (from SunPro).

However, if is not clear which standard you mean by 'ISO C': assuming 
C99 is fairly safe, but GNU extensions from C99 are not -- nested 
functions are one such.

> [Incidentally, when I use a makevars.win file to include these gcc 
> options in Rcmd build etc. the problem with variable-length arrays 
> is not flagged; maybe my command-line gcc is a different version 
> from that in Rtools]

Well, you (and only you) can easily check that for yourself, but the 
other flags also matter, especially --std.  Because it has been needed 
for the use of the MinGW headers, R on Windows is built with 
--std=gnu99.  (Linux headers have a similar problem: using --std=c99 
disables some features we test for in configure and wish to use -- and 
there are OS features, not language extensions.)

>
> Murray Efford
> University of Otago
> Dunedin, New Zealand
> murray.efford at otago.ac.nz<mailto:murray.efford at otago.ac.nz>
>
> 	[[alternative HTML version deleted]]

Please note what the posting guide has to say about that.

>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



[Rd] Compatibility of external C code across platforms
Prof Brian Ripley