[Rd] Compatibility of external C code across platforms

Prof Brian Ripley ripley at stats.ox.ac.uk
Sat Sep 26 11:40:11 CEST 2009

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

More information about the R-devel mailing list