Thread View: comp.os.msdos.programmer
2 messages
2 total messages
Started by Robert Mascaro
Mon, 25 Jan 1993 04:09
Borland C++'s printf
Author: Robert Mascaro
Date: Mon, 25 Jan 1993 04:09
Date: Mon, 25 Jan 1993 04:09
12 lines
966 bytes
966 bytes
I am not sure that this is the right group but here goes.
I am writing a TSR using C++ (borland's) and are having trouble with the
printf statement. I am outputing integer variables to the screen and
need a printf("%i",x) etc statement. The problem is that it crashes at
the point of output each time. I have tryed a "cputs" to test the
problem and this works fine, however any printf statement will crash the
machine.
As background, the TSR I mentioned makes a clock tick on the screen
while using DOS.
Any suggestions, advice??
Thanks in advance,
Rob.
Re: Borland C++'s printf
Author: Scott Mark
Date: Tue, 26 Jan 1993 10:21
Date: Tue, 26 Jan 1993 10:21
51 lines
2544 bytes
2544 bytes
In article <1jvp5jINNe3q@uniwa.uwa.edu.au> rmascaro@uniwa.uwa.edu.au (Robert Mascaro) writes:
>I am not sure that this is the right group but here goes.
>I am writing a TSR using C++ (borland's) and are having trouble with the
>printf statement. I am outputing integer variables to the screen and
>need a printf("%i",x) etc statement. The problem is that it crashes at
>the point of output each time. I have tryed a "cputs" to test the
>problem and this works fine, however any printf statement will crash the
>machine.
>As background, the TSR I mentioned makes a clock tick on the screen
>while using DOS.
>Any suggestions, advice??
>Thanks in advance,
>Rob.
This may help to explain the problem- it may not.
When you try using things like printf() in a TSR you run the risk of
interfering with another "thread" of the function that is running in
the foreground.
There are two ways of preventing disaster in this case. The simplest way
is to have a semaphore that all the threads fight over. A semaphore works
the same way as a railroad semaphore -- the guy with the green light gets
to go and everyone else waits to use the track.
When you use a semaphore, you are free to declare local static data
foo()
{
static char data[36];
}
because only your thread will be writing into that area.
A slightly more complicated way to do this is to write the functions to
be "re-entrant", which means that there is no static local data used by
the function (or any functions that it calls). With a re-entrant function,
each thread has its own copy of the data on the stack, so the threads don't
interfere with each other's variables.
If memory serves, the printf() function for Microsoft C6 was written to
be re-entrant. I wouldn't bet your purchase price for C7 on it, though.
It's been a long time since I've been in contact with Peter Golde, who
wrote the thing.
It's common for routines like printf() to either use static data areas or
to call functions that do. This may be what is happening to your TSR.
Have you tried using sprintf() and then cputs()? You may have to write
your own routine to do this job.
Scott Mark
sjm@miles.com
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads