ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ Innovative Data Concepts, Inc. Technical Information Note TesSeRact Development Tools ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ Using Compiler Switches with TCXL TN-9206-007 June 5, 1992 ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ In this Tech Note, we will explain the compiler switches that we use to build TCXL-DOS libraries. Most are applicable and recommended for your use in compiling your applications. (If you use MAKEGEN.BAT and GEN.SMF to build your TCXL programs, as described in Tech Note TN-9204-004, you will already be using these switches, but may wish to understand them better anyway.) Turbo C/C++ & Borland C++ Compiling for debugging: -c -m -DTCXLDBG -v -K -w -d -N- -k- -IINC -I. -DTCXL -O -Z Compiling for production: -c -m -K -w -d -N- -k- -IINC -I. -DTCXL -O -Z Explanation: Switch Meaning ====== ======= -c Compile without linking -m Memory model, where is s, c, m, l, or h -DTCXLDBG Preprocessor definition to activate TCXL debugging code (debugging only) -v Compile for debugger (debugging only) -K Treat characters as unsigned by default -w All warnings on -d Merge duplicate strings -N- Don't check for stack overflow -k- Don't use standard stack frame -IINC Look for header files in the INC directories (only valid if you're working in the TCXL root directory) -I. Look for header files in the current directory -DTCXL Preprocessor definition used for conditional TN-9206-007 Page 2 compilation within the library -O Optimize jumps -Z Optimize register usage Notes: 1. The '-w' setting is highly recommended. In general, we recommend that you use the highest levels of warnings that your compiler can produce. 2. The '-d' setting is safe to use so long as you don't attempt to modify static strings within your program. 3. The '-N-' and '-k-' settings are used because enabling these options adds bulk to your program. If you want to allow these settings to active (which is the default), it's up to you -- just don't compile the library that way! 4. The optimization setting we use here ('-O' and '-Z') represent settings that in our experience we have found to be generally "safe". You may find that other optimizations settings work just fine for your applications, but we recommend that you stick with these setting when building TCXL libraries, since optimizers have been known to break existing code! 5. When compiling a huge-model TCXL library, you must use the settings -zR_DATA -zTDATA in addition to '-mh'. Without going into all the details, this is part of a scheme that we use to allow assembler modules to link correctly with C modules in huge model. Microsoft 5.1, 6.x, and 7.0, Quick C Compiling for debugging: /c /A /Od /DTCXLDBG /Zi /J /Gs /W[3 | 4] /IINC /I. /DTCXL /Zp1 Compiling for production: /c /A /O[ils | x] /J /Gs /W[3 | 4] /IINC /I. /DTCXL /Zp1 Explanation: Switch Meaning ====== ======= /c Compile without linking TN-9206-007 Page 3 /A Memory model, where is s, c, m, l, or h /Od No optimization (debugging only) /Oils Optimization: use intrinsic functions, loop optimization, and optimize for speed (MSC 5.1 and 6.0x, non-debugging only) /Ox Full optimization (MSC 7.0, non-debugging only) /DTCXLDBG Preprocessor definition to activate TCXL debugging code (debugging only) /Zi Compile for debugger (debugging only) /J Treat characters as unsigned by default /Gs Turn off stack checking /IINC Look for header files in the INC directories (only valid if you're working in the TCXL root directory) /I. Look for header files in the current directory /DTCXL Preprocessor definition used for conditional compilation within the library /Zp1 Pack structures on one 1-byte boundary (i.e., byte alignment) Notes: 1. The '/Wn' setting establishes the compiler's warning. For MSC 5.1 the highest setting is 3; for MSC 6.x and 7.0 4 is the highest setting (although we use /W3 for MSC 7.0). 2. We have had problems with buggy optimization in MSC 5.1 and 6.x, forcing us to limit optimizations to '/Oils'. Within certain library modules compiled with MSC 6.x, in fact, we even have to disable loop optimizations. In MSC 7.0, however, we have found that the optimizations produce more reliable code, and therefore use full optimization. 3. We disable stack checking with the '/Gs' switch because it adds extra code. 4. The '/Zp1' setting is very important for TCXL library code. Many data structures in the library are accessed by both C and assembler, so the compiler must not be allowed to pad them. Instead, all TCXL data structures are carefully hand-constructed to align members to word boundaries. TN-9206-007 Page 4 Zortech C/C++ Compiling for debugging: -c -m -DTCXLDBG -g -o-all -J -Ju -w- -r -a1 -IINC -I. -s- -S- -v0 -DTCXL Compiling for production: -c -m -o-liv -o-loop -J -Ju -w- -r -a1 -IINC -I. -s- -S- -v0 -DTCXL Explanation: Switch Meaning ====== ======= -c Compile without linking -m Memory model, where is si, ci, mi, li, or hi -DTCXLDBG Preprocessor definition to activate TCXL debugging code (debugging only) -g Compiler for debugger (debugging only) -o-all No optimization (debugging only) -o-liv Loop invariant optimization (non-debugging only) -o-loop Multi-pass optimization (non-debugging only) -J Use unsigned chars -Ju Make char == unsigned char (for C++ type checking) -w- Turn on all compiler warnings -r Enforce strict function prototyping -a1 Use byte alignment -s- Disable stack checking -S- Don't use standard stack frame -v0 Compile quietly (no unnecessary messages) -IINC Look for header files in the INC directories (only valid if you're working in the TCXL root directory) -I. Look for header files in the current directory TN-9206-007 Page 5 -DTCXL Preprocessor definition used for conditional compilation within the library Notes: 1. Comments made for the previous compilers regarding byte alignment, stack checking, and stack frames apply here as well. Watcom C Compiling for debugging: /c /m /dTCXLDBG /d2 /i=INC -i=. /w4 /zp1 /zq /dTCXL Compiling for production: /c /m /oaxt /i=INC -i=. /w4 /zp1 /zq /dTCXL Explanation: Switch Meaning ====== ======= /c Compile without linking /m Memory model, where is s, c, m, l, or h /dTCXLDBG Preprocessor definition to activate TCXL debugging code (debugging only) /d2 Compiler for debugger (debugging only) /oaxt Full optimization with aliasing, optimized for speed (non-debugging only) /i=INC Look for header files in the INC directories (only valid if you're working in the TCXL root directory) -i=. Look for header files in the current directory -w4 Turn on all compiler warnings -zp1 Byte alignment /zq Compile quietly (no unnecessary messages) Notes: TN-9206-007 Page 6 1. Regarding byte alignment, see the notes for the Microsoft compilers. JPI TopSpeed C/C++ Compiling for debugging: /m /ox- /dTCXLDBG /v2 /b /j+ /w+ /zq /m /dTCXL Compiling for production: /m /j+ /w+ /zq /m /dTCXL Explanation: Switch Meaning ====== ======= /m Memory model, where is s, c, m, l, or x /ox- No optimization (debugging only) /dTCXLDBG Preprocessor definition to activate TCXL debugging code (debugging only) /v2 Compile for debugger (debugging only) /b Put line number information in .OBJ files (debugging only) /j+ Make chars unsigned /w+ Turn on all compiler warnings /zq Compile quietly (no unnecessary messages) /m Make (see below) Notes: 1. Unlike the other compilers, TopSpeed C uses full optimization by default. 2. The '/m' (make) switch is used to tell the compiler to use JPI's project system. Of course, if you want to compile your own application, you must make you own project file.