dos_compilers/Borland Turbo C v2/HELPME!.DOC
2024-07-02 06:22:27 -07:00

479 lines
18 KiB
Plaintext
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

TURBO C 2.0: ANSWERS TO COMMON QUESTIONS
G e t t i n g S t a r t e d
----------------------------------------------------------------------
Q. How do I install Turbo C?
A. Run the INSTALL program from the INSTALL/HELP disk. To start
the installation, change your current drive to the one that
has the install program on it and type INSTALL. You will be
given instructions in a box at the bottom of the screen for
each prompt. For example, if you will be installing from
drive A:, type:
A:
INSTALL
At this point, the INSTALL program will appear with menus
selections and descriptions to guide you through the installation
process.
Q. How do I run Turbo C?
A. After you have installed Turbo C, type "TC" from the DOS
prompt and you're ready to go. Chapter 2 (Getting Started)
of the Turbo C User's Guide will guide you through your
first Turbo C program.
Q. What is the difference between TC.EXE and TCC.EXE?
A. The Turbo C package comes with two compilers, an Integrated
Environment named TC.EXE and a command-line compiler named
TCC.EXE. The Integrated Environment is essentially
the command-line compiler with an integrated editor,
linker, and debugger. Please refer to the Turbo C
User's Guide for details on using both systems.
Q. What is a configuration file?
A. A configuration file tells Turbo C what options to default to
and where to look for its library and header files. TC.EXE
looks for a configuration file named TCCONFIG.TC, and
TCC.EXE looks for a file named TURBOC.CFG. See the User's
Guide, pages 40 and 143 for more information.
Q. How do I create a configuration file?
A. When you run the INSTALL program it creates a configuration
file named TURBOC.CFG for TCC.EXE. This file is just an
ASCII file which you can change with any text editor. It
contains the path information for the library and header
files for TCC.EXE to use. The INSTALL program does not
create a TCCONFIG.TC file for TC.EXE because it installs
the directory information directly into TC.EXE. You can
create a configuration file for TC.EXE by running TC,
setting your options however you want to set them, and
typing Alt-O/S.
I n t e g r a t e d E n v i r o n m e n t
----------------------------------------------------------------------
Q. Why is Turbo C not able to find any of my #include files?
A. The compiler searches for include files in the Turbo C Include
Directories. This option is specified under the Options/Directories
menu. The INSTALL program initially sets this option to the
directory where it copied all the Turbo C *.h files.
Q. Why do I get the message:
Linker Error: Unable to open input file 'C0x.OBJ'
A. The linker searches for Turbo C start-up and library files in the
Turbo C Library Directories. This option is specified under the
Options/Directories menu. The INSTALL program initially sets this
option to a directory where it copied the start-up and library
files.
Q. How do I get Turbo C to link in my own libraries or use multiple
source files?
A. Turbo C's Project facility is designed to allow you to work with
multiple files. Refer to Chapter 3 of the Turbo C User's Guide,
under "Projects: Using Multiple Source Programs".
Q. Why does the linker tell me that all the graphics library
routines are undefined?
A. The Options/Linker/Graphics Library item must be set ON, if
you are using any Turbo C graphics functions and have not
specifyed GRAPHICS.LIB in a project file.
Q. Why does Turbo C report "Unable to open include file 'stdarg.h'"
when I try to #include <stdio.h>?
A. The most probable reason is that you have exceeded the number
of files that DOS can have open simultaneously. Add the line
FILES=20
to your DOS CONFIG.SYS file. This allows DOS to open up to 20
files at the same time. CONFIG.SYS will only be effective
after you have rebooted your computer. See the IBM DOS Reference
Manual for details on the CONFIG.SYS file.
Q. How do I change the colors of the editor and menus in TC?
A. The utility TCINST.EXE allows you to customize your colors.
Q. How do I get a listing of my source code to my printer?
A. From within the Turbo C editor hit <Ctrl><K><P>. This will
print a marked block to the printer. If no block is marked
this key sequence will print the entire file in your editor.
Q. When I Make, Run, or Trace a program Turbo C sometimes goes
through the compile and link process even when the object files
are up-to-date.
A. Turbo C's MAKE logic works solely on a file's date and time
stamp. If one of your source files is marked with a date
that's sometime in the future, the object files that are
created from it will always be older than the source file,
and Turbo C will always try to rebuild the file. You can fix
this by using TOUCH.COM to set the file to the current date
and time. You should also make sure that your system's date
and time are always properly set.
C o m m a n d - L i n e C o m p i l e r
----------------------------------------------------------------------
Q. Why is Turbo C not able to find any of my #include files?
A. The compiler searches for include files in the Turbo C Include
Directories. This option is specified by the -I switch. The INSTALL
program initially writes a configuration file (TURBOC.CFG) that
sets this to the directory where it copied all the Turbo C *.h
files.
Q. Why do I get the message:
Linker Error: Unable to open input file 'C0x.OBJ'
A. The linker searches for Turbo C start-up and library files in the
Turbo C Library Directories. This option is specified by the -L
switch. If you allow TCC to invoke the linker, it will search the
directories in the configuration file (TURBOC.CFG) written by the
INSTALL program. If you run TLINK, the configuration file is not read.
Q. Why does the linker tell me that all the graphics library
routines are undefined?
A. TCC will not search the graphics library unless you tell it to.
You should specify the graphics library on the command line. For
example, to compile BGIDEMO, type
TCC BGIDEMO.C GRAPHICS.LIB<Enter>
G e n e r a l I / O
----------------------------------------------------------------------
Q. The '\n' in cprintf() does not return the cursor to the
beginning of the line. It only moves the cursor down one line.
A. cprintf() no longer interprets '\n' as a Carriage Return/
Line Feed combination. The '\n' only outputs a Line Feed. To
force the cursor to the beginning of the line, manually
insert a Carriage Return:
cprintf("\n\r");
Q. How do I print to the printer from a Turbo C program?
A. Turbo C uses a FILE pointer (stdprn) defined in the STDIO.H
file. You do not need to open stdprn before using it:
#include <stdio.h>
main()
{
fprintf(stdprn, "Hello, world\n");
}
Note that if your printer is line-buffered, the output is
flushed only after a '\n' is sent.
Q. I am reading and writing binary files. My program is
translating the Carriage Return (0x0D) and Line Feed (0x0A)
characters. How do I prevent this from happening?
A. Files opened in text mode will translate these characters for
DOS. To read a file in binary mode, open it in binary mode.
For example
#include <stdio.h>
main()
{
FILE *binary_fp;
char buffer[100];
binary_fp = fopen("MYFILE.BIN", "rb");
fread(buffer, sizeof(char), 100, binary_fp);
:
}
The default file mode is text.
Q. Why don't printf() and puts() print text in color?
A. Use the console I/O functions cprintf() and cputs() for color output.
#include <conio.h>
main()
{
textcolor(BLUE);
cprintf("I'm blue.");
}
Q. How do I print a long integer?
A. Use the "%ld" format:
long int l = 70000L;
printf("%ld", l);
Q. How do I print a long double?
A. Use the "%Lf" format.
long double ldbl = 1E500;
printf("%Lf", ldbl);
E x a m p l e P r o g r a m s
----------------------------------------------------------------------
Q. How do I compile the MICROCALC spread sheet?
A. See Appendix G of the Turbo C Reference Manual.
Q. How do I compile the BGIDEMO program?
A. 1. Make sure that the following Turbo C files are in your
current directory:
BGIDEMO.C
*.BGI
*.CHR
2. Run TC.
3. Load BGIDEMO.C into the Editor by hitting F3 then typing
BGIDEMO<Enter>
3. Go to the Run menu and choose the Run item.
Q. How do I create a COM file?
A. DOS versions 3.2 and earlier include an EXE2BIN utility that
converts EXE files to COM files. For users who do not have
EXE2BIN, the Turbo C command-line linker, TLINK will create
a COM file instead of an EXE file if the /t option is
specified. For example:
tcc -mt -lt tiny
will create TINY.COM instead of TINY.EXE.
There are certain limitations in converting an EXE file to a COM
file. These limitations are documented in the IBM Disk Operating
System manual under EXE2BIN.
Turbo C's TINY model is compatible with the COM format, but programs
that use Turbo C's floating point routines cannot be converted to a
COM file.
G r a p h i c s
----------------------------------------------------------------------
Q. Why do I get the error message:
BGI Error: graphics not initialized (use 'initgraph')
when I use a graphics function? My program has already
called initgraph().
A. For some reason initgraph() failed. To find out why, check
the return value of graphresult(). For example:
#include <graphics.h>
main()
{
int gerr; /* graphics error */
int gdriver = DETECT, gmode;
/* Initialize graphics using auto-detection and look
for the .BGI and .CHR files in the C:\TURBOC directory.
*/
initgraph(&gdriver, &gmode, "C:\\TURBOC");
if ((gerr = graphresult()) != grOk)
{
printf("Error : %s\n", grapherrormsg(gerr));
exit(1);
}
:
}
M a t h / F l o a t i n g P o i n t
----------------------------------------------------------------------
Q. Why do I get incorrect results from all the math library
functions like cos() and tan()?
A. You must #include <math.h> before you call any of the standard
Turbo C math functions. In general, Turbo C assumes that a function
that is not declared returns an int. In the case of math functions,
they usually return a double. For example
/* WRONG */ /* RIGHT */
#include <math.h>
main() main()
{ {
printf("%f", cos(0)); printf("%f", cos(0));
} }
Q. How do I "trap" a floating point error?
A. See the signal() and matherr() functions in the Turbo C Reference
Guide. The signal() function may be used to trap errors in the
80x87 or the 80x87 emulator. The matherr() function traps errors
in the Math Library functions.
L i n k e r E r r o r s
----------------------------------------------------------------------
Q. Why do I get the message:
Linker Error: Unable to open input file 'C0x.OBJ'
A. See "Integrated Environment" section above.
Q. Why do I get the message:
Linker Error: Undefined symbol '_main' in module C0
A. Every C program must contain a function called main(). This
is the first function executed in your program. The function
name must be all in lower case. If your program does not
have one, create one. If you are using multiple source files,
the file that contains the function main() must be one of
the files listed in the Project.
Note that an underscore character '_' is prepended to all
external Turbo C symbols.
Q. Why does the linker tell me that all the graphics library
routines are undefined?
A. See the "Integrated Environment" and "Command-line Compiler"
sections above.
Q. What is a 'Fixup overflow'?
A. See the listing of TLINK error messages in Appendix D of the
Turbo C Reference Guide.
Q. I am linking my own assembly language functions with Turbo C.
The linker reports that all of my functions are undefined.
A. Make sure that you have put an underbar character '_' in front of all
assembly language function names to be called by Turbo C. Your assembly
language program should be assembled with Case Sensitivity. See
the Chapter 12, "Advanced Programming," in the Turbo C User's Guide
for details.
O t h e r Q u e s t i o n s
----------------------------------------------------------------------
Q. How do I change the stack size?
A. The size of the stack of a Turbo C program is determined at
run-time by the global variable _stklen. To change the size
to, for example 10000 bytes, include the following line in
your program:
extern unsigned _stklen = 10000;
This statement must not be inside any function definition.
The default stack size is 4096 bytes (4K).
Q. I'm getting a 'Stack Overflow!' message when I run my program.
How can I work around this?
A. You may increase the stack size by following the procedure above. Stack
overflows are usually caused by a large amount of local data or
recursive functions. You can decrease the amount of stack space
used by declaring your local variables static:
main() main()
{ {
char x[5000]; --> static char x[5000];
: :
} }
Of course, you should be aware that there are other effects
that the "static" keyword has, as applied here.
Q. My program comes up with the message 'Null pointer assignment'
after it terminates. What does this mean?
A. Before a small-data model Turbo C program returns to DOS, it will
check to see if the beginning of its data segment has been corrupted.
This message is to warn you that you have used uninitialized pointers
or that your program has corrupted memory in some other way.
Q. Why are .EXE files generated by TC.EXE larger than those
generated by TCC.EXE?
A. In the default configuration, TC.EXE includes debugging
information in the .EXE files that it creates, and TCC.EXE
does not. If you don't want to produce this debugging
information, you can shut it off in the Integrated
Development Environment by selecting Alt-D/S/N.
Q. Why do I get "declaration syntax error" messages on DOS.H?
A. You have set the "Ansi keywords only" option ON. Keep this option
OFF when using any keywords specific to Turbo C .
Q. I have a working program that dynamically allocates memory
using malloc() or calloc() in small data models (tiny, small,
and medium). When I compile this program in large data models
(compact, large, and huge) my program hangs.
A. Make sure that you have #include <alloc.h> in your program.
Q. I am linking my own assembly language functions with Turbo C.
But the linker reports that all of my functions are undefined.
A. See answer above in the "Linker" section.
Q. My far pointers "wrap around" when they are incremented over 64K.
How do I reference a data object that is greater than 64K?
A. Use huge pointers.
Q. Can I declare more than 64K of global variables?
A. You may have a total of up to 64K global and static data in
the Tiny, Small, Medium, Compact and Large memory models. In
the Huge model, the maximum is 64K per source module.
Q. How do I declare an array that's greater than 64K?
A. Arrays greater than 64K must be allocated off the heap. If,
for example you wanted a two-dimensional array of characters
that was 1024 by 128, the declaration you would expect to
write would be:
char array[1024][128];
But since the size of this array is greater than 64K, it must
be allocated off the heap. An example of this is:
#include <alloc.h>
char (huge *array)[128];
:
main()
{
:
array = farcalloc(sizeof(*array), 1024);
:
}
The array can be accessed with the same code as an array not
allocated off the heap. For example:
i = array[30][56];
will assign "i" the value stored at the 31st by 57th element
in "array".
The use of the "huge" keyword is necessary in the declaration
of "array" since only a huge pointer can address objects
greater than 64k. For further discussion of huge pointers,
refer to the User's Guide.
Q. How do I interface Turbo C routines to a Turbo Pascal program?
A. See the example programs CPASDEMO.PAS and CPASDEMO.C on disk.
These files are packed in the file EXAMPLES.ARC and you will
need to UNPACK them before using them.
Q. How do I get Clipper to link with Turbo C?
A. If you are having trouble, contact Nantucket Technical Support.