Professional Documents
Culture Documents
Helpme!
Helpme!
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>
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 */
main()
{
printf("%f", cos(0));
}
/* RIGHT */
#include <math.h>
main()
{
printf("%f", cos(0));
}
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()
{
char x[5000];
:
}
-->
main()
{
static char x[5000];
:
}
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.