-
Notifications
You must be signed in to change notification settings - Fork 18
/
c-and-fortran.Rmd
53 lines (33 loc) · 1.85 KB
/
c-and-fortran.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# C and Fortran code {#c-fortran}
If the package contains C or Fortran code, it should adhere to the standards and
methods described in the [System and foreign language interfaces][CRAN foreign]
section of the [Writing R Extensions][] manual.
We emphasize particular points in the following sections.
### Internal functions
Use internal <i class="fab fa-r-project"></i> functions, e.g., `R_alloc` and random number generators (RNGs), over system-supplied ones.
### C function registration
Use C function registration (See the [Registering native routines][] section of
the [Writing R Extensions][] manual).
### Checks for user interruption
Use `R_CheckUserInterrupt()` in C level loops when there is a chance that they may not terminate for certain parameter settings or when their run time exceeds 10 seconds with typical parameter settings, and the method is intended for interactive use.
### Makevars
Make judicious use of the `Makevars` and `Makefile` files within a package.
These are often not required at all (See the [Configure and cleanup][CRAN config] section of the [Writing R Extensions][] manual).
### Warnings and optimizations
During package development, enable all warnings and disable optimizations.
If you plan to [use a debugger](#debugging-cc-code), tell the compiler to
include debugging symbols.
The easiest way to enforce these is to create a user-level `Makevars` file user’s home directory in a sub-directory called ‘.R’). See examples below for flags for common toolchains.
Consult the section about [Makevars files][] in the [Writing R Extensions][] manual.
Example for gcc/g++:
```
CFLAGS=-Wall -Wextra -pedantic -O0 -ggdb
CXXFLAGS=-Wall -Wextra -pedantic -O0 -ggdb
FFLAGS=-Wall -Wextra -pedantic -O0 -ggdb
```
Example for clang/clang++:
```
CFLAGS=-Weverything -O0 -g
CXXFLAGS=-Weverything -O0 -g
FFLAGS=-Wall -Wextra -pedantic -O0 -g
```