13. Preparing Code for Use with Reactis for C#
Although Reactis for C supports a very large subset of C language features and standard runtime library functions, not every C program can be immediately used with Reactis for C. Before using Reactis for C on a C program or program fragment, you must first ensure that the portion of the program to be used with Reactis for C does not depend on any unsupported features.
The following is a quick summary of the requirements for using Reactis for C:
No binary code. Because Reactis for C compiles code into its own internal virtual machine code, only the portion of a program for which source code is available can be used with Reactis for C.
No threads. Currently, Reactis for C does not support multi-threaded code. It is of course possible to extract single-threaded components of multi-threaded programs for testing with Reactis for C.
Must use the Reactis for C standard libraries. Like most C compilers, Reactis for C provides its own implementation of the C runtime library (
libc
) and math library (libm
). The C program under test will be automatically linked with these libraries. While most of the standard library functions are implemented, there are some unsupported library functions. These are listed in the Unsupported C Features section.No file I/O. The Reactis for C paradigm requires that all data passed to/from the code under test pass through the harness, so that test suites can be generated. Hence, reading or writing data via the C standard I/O library is not allowed.
No Clocks. Use of the clock functions provided by
time.h
will result in tests which are not reproducible. For this reason, they should not be used in Reactis for C.
13.1. Basic type sizes and alignments#
The sizes and alignments of the common built-in C types under Reactis
for C are listed in Table Table 13.1. These match the
behavior of GCC (GNU C Compiler) and most other x86 C
compilers. Integers are stored using a little endian
byte order (the
least-significant byte is stored first).
Type |
sizeof |
alignof |
---|---|---|
char, bool, void |
1 |
1 |
short int |
2 |
2 |
int, long int, float |
4 |
4 |
long long int, double, long double* |
8 |
8 |
\(^*\) long double is not currently supported – it is mapped to type double.
13.2. Unsupported C Features#
Reactis for C supports a very large subset of the C99 standard. The following features, however, are not currently supported:
Variable-length arrays (e.g.,
int f(int n) { char s[n]; }
).ANSI Trigraphs.
Universal character codes (a
\u
or\U
escape which can be followed by a UCS-2 or UCS-4 hex code).Signals.
Types
_Complex
and_Imaginary
.Type
long double
.Wide character types.
File I/O during simulation.
Designated initializers (e.g., struct
{ int x; int y; } s = { .y = 5 };
).Non-constant static initializers (e.g.,
static int A[1] = { f(x); };
).
13.3. Supported C library functions#
The following C library functions are currently provided by Reactis for C.
- assert.h
assert
- ctype.h
isalnum isalpha isascii iscntrl iscsym iscsymf isdigit isxdigit isprint isgraph ispunct islower isupper isspace isblank toint tolower toupper
- errno.h
strerror
- fcntl.h
fileno
- fenv.h
fegetround fesetround
- math.h
acos acosf acosl asin asinf asinl atan atan2 atan2f atan2l atanf atanl cbrt cbrtf cbrtl ceil ceilf ceill copysign copysignf copysignl cos cosf cosh coshf coshl cosl exp exp2 exp2f exp2l expf expl fabs fabsf fabsl fdim fdimf fdiml floor floorf floorl fmax fmaxf fmaxl fmin fminf fminl fmod fmodf fmodl fpclassify frexp frexpf frexpl isfinite isgreater isgreaterequal isinf isless islessequal islessgreater isnan isnormal isunordered ldexp ldexpf ldexpl llrint llrintf llrintl ln lnf lnl log log2 log2f log2l log10 log10f log10l logf logl lrint lrintf lrintl lround lroundf lroundl modf modff modfl nan nanf nanl nextafter nextafterf nextafterl nexttoward nexttowardf nexttowardl pow powf powl remainder remainderf remainderl remquo remquof remquol round roundf roundl scalbln scalblnf scalblnl scalbn scalbnf scalbnl signbit sin sinf sinh sinhf sinhl sinl sqrt sqrtf sqrtl tan tanf tanh tanhf tanhl tanl trunc truncf truncl
- memory.h
bcopy memccpy
- setjmp.h
longjmp setjmp
- stdarg.h
va_arg va_copy va_end va_start
- stddef.h
offsetof
- stdint.h
INT8_C INT16_C INT32_C INT64_C INTMAX_C UINT8_C UINT16_C UINT32_C UINT64_C UINTMAX_C
- stdio.h
snprintf sprintf
- stdlib.h
_Exit abort abs atof atoi atol atoll bsearch calloc div exit free getenv labs ldiv llabs lldiv malloc mblen mbstowcs mbtowc qsotr rand realloc srand strtod strtof strtol strtold strtoll strtoul strtoull wcstombs
- string.h
memchr memcmp memcpy memmove memset strcat strchr strcmp strcoll strcpy strcspn strdup strlen strncat strncmp strncpy strndup strpbrk strrchr strspn strstr strtok strxfrm
- tgmath.h
acos asin atan atan2 cbrt ceil copysign cos cosh erf erfc exp exp2 expm1 fabs fdim floor fma fmax fmin fmod frexp hypot ilogb ldexp lgamma ln log log1p log2 lrint lround modf nearbyint nextafter nexttoward pow remainder remquo rint round scalbn scalbnln sin sinh sqrt tan tanh tgamma trunc
13.4. Unsupported Library Functions#
The following C runtime library functions are not supported:
- complex.h
cabs cabsf cabsl cacos cacosf cacosh cacoshf cacoshl cacosl carg cargf cargl casin casinf casinh casinhf casinhl casinl catan catanf catanh catanhf catanhl catanl ccos ccosf ccosh ccoshf ccoshl ccosl cexp cexpf cexpl cimag cimagf cimagl clog clogf clogl conj conjf conjl cpow cpowf cpowl cproj cprojf cprojl creal crealf creall csin csinf csinh csinhf csinhl csinl csqrt csqrtf csqrtl ctan ctanf ctanh ctanhf ctanhl ctanl
- dlfcn.h
dlclose dlerror dlopen dlsym
- errno.h
perror
- fcntl.h
creat fcntl open close read write lseek unlink
- locale.h
localeconv setlocale
- math.h
acosh acoshf acoshl asinh asinhf asinhl atanh atanhf atanhl erf erfc erfcf erfcl erff erfl expm1 expm1f expm1l fma fmal fmaf hypot hypotf hypotl ilogb ilogbf ilogbl lgamma lgammaf lgammal log1p log1pf log1pl rint rintf rintl tgamma tgammaf tgammal
- setjmp.h
sigsetjmp siglongjmp
- signal.h
raise
- stdio.h
clearerr fclose feof ferror fflush fgetc fgetpos fgets fopen fprintf fputc fputs fread freopen fscanf fseek fsetpos ftell fwrite getc getchar gets printf putc putchar puts remove rename rewind scanf setbuf setvbuf tmpfile tmpname ungetc vfscanf vscanf vsscanf
- stdlib.h
atexit bsearch execl execle execlp execv execve execvp qsort system
- tgmath.h
carg cimag creal conj cproj
- unistd.h
access alarm brk chdir chown chroot close confstr crypt ctermid cuserid dup dup2 encrypt fchdir fchown fdatasync fork fpathconf fsync ftruncate getcwd getdtablesize getegid geteuid getgid getgroups gethostid getlogin getlogin_r getpagesize getpass getpgid getpgrp getpid getppid getsid getuid getwd isatty lchown link lockf lseek nice pathconf pause pipe pread pthread_atfork pwrite read readlink rmdir sbrk setgid setpgid setpgrp setregid setreuid setsid setuid sleep swab symlink sync sysconf tcgetpgrp tcsetpgrp truncate ttyname ttyname_r ualarm unlink usleep vfork write
- utime.h
utime
- wchar.h
fgetwc fgetws fputwc fputws fwide fwprintf fwscanf getwc getwchar putwc putwchar swprintf swscanf ungetwc vfwprintf vfwscanf vswprintf vswscanf vwprintf vwscanf wcscat wcschr wcscmp wcscoll wcscpy wcscspn wcslen wcsncat wcsncmp wcsncpy wcspbrk wcsrchr wcsspn wcsstr wcstok wcsxfrm wmemchr wmemcmp wmemcpy wmemmove wmemset wprintf wscanf
- wctype.h
btowc iswalnum iswalpha iswcntrl iswctype iswdigit iswgraph iswlower iswprint iswpunct iswspace iswupper iswxdigit mbrlen mbrtowc mbsinit towctrans towlower towupper wcrtomb wctob wctrans wctype
- time.h
asctime clock ctime difftime gmtime localtime mktime time strftime