Cortex code:testing with gcc
From WikiHistedOrg
It is possible to pass Cortex timing code through the GCC compiler to check it for errors.
You need to download one include file: gcc-compat.h.
Contents |
[edit] Example
First, get the file gcc-compat.h. (The most up-to-date example will be found in the first block of comments of the gcc-compat.h file.)
Type the following at a shell prompt all on one line, and replace "sacst-h.tm1" with the timing file you want to test.
gcc -x c -Wall -Wno-implicit -Wno-main -Wunused-macros -fno-builtin -include gcc-compat.h -I . -c -o /tmp/gcc-preppy.out sacst-h.tm1 2>&1 | less
[edit] How to get GCC
Under Unix: should be installed by default, or use your local package manager to install it.
Under Windows: install the gcc package from Cygwin, open up a "bash shell", change to the directory with your code, then type the above line.
[edit] Strategy used by gcc-compat.h
C compilers have three stages: a preprocessing step, a compiling step and a linking step.
The idea is to skip the linking step, and have GCC preprocess and compile the code, generating warnings as it goes. The resulting compiled code is discarded, we only care about the error messages.
[edit] Possible problems
[edit] main() error
You will definitely get an error about main() not being defined correctly, something like:
./sacst.tmc:68: warning: return type defaults to `int' ./sacst.tmc: In function `main': ./sacst.tmc:97: warning: control reaches end of non-void function
Just ignore it.
This happens because Cortex uses the definition main(), and as gcc says, the return type defaults to int, not void. Meanwhile, the ANSI C standard uses
int main (void).
See a copy of K&R for more details.
[edit] May need to extend gcc-compat.h
I haven't exhaustively defined all the symbols used in Cortex. I did a quick pass through ufnlist.c. You may have to define others.
[edit] References
- Kernighan and Ritchie, The C Programming Language (the standard ref)
- Harrison and Steele, C: A Reference Manual (the best ref on questions of portability and how to write C that runs on different compilers. This is an issue because Cortex is pretty non-standard.)

