Debug Console DELAY?

Hi there,

I found the debug console has some problems. When I use printf() or
cout, the outputs to the concole seemed to be buffered and do not show
immediately, You need to terminal the program to see the result, or need
to print a lot of thing to “push” the result out.

PLS try the small codes below, and set a breakpoint at the line
return. When you debug and run it, it supposed to display “Please enter
the number you want to display” immediately, but, in fact, there is
nothing. If you input “10”, you will get nothing before you resume the
code and let it terminate. And if you input “100”, you can see
something, and the last line will be: 93^2= 8649, then if you resume the
code and let it terminate, you can see all the result.

And the fact is, if you run the file directly in terminal window,
everything is OK.

Any suggestions? Should I set something to bypass the buffer?

Best regards

Ling


#include <stdlib.h>
#include <stdio.h>

int main(int argc, char argv[]) {
int i,j;
printf(“Please enter the number you want to display:”);
scanf("%d",&j);
printf("\n");
for (i= 0 ;i<j;i++)
printf("%d^2= %d\n",i,i
i);
return EXIT_SUCCESS;
}

I was told by the help group that this was a known problem that would be
fixed in a future release. Here is the workaround they gave me (you need to
call it once for each thread that uses stdout):

setvbuf (stdout, NULL, _IOLBF, 0);

Best regards,

Lisa

“Ling Shen” <ling@ece.concordia.ca> wrote in message
news:3EE101B9.8080607@ece.concordia.ca

Hi there,

I found the debug console has some problems. When I use printf() or
cout, the outputs to the concole seemed to be buffered and do not show
immediately, You need to terminal the program to see the result, or need
to print a lot of thing to “push” the result out.

PLS try the small codes below, and set a breakpoint at the line
return. When you debug and run it, it supposed to display “Please enter
the number you want to display” immediately, but, in fact, there is
nothing. If you input “10”, you will get nothing before you resume the
code and let it terminate. And if you input “100”, you can see
something, and the last line will be: 93^2= 8649, then if you resume the
code and let it terminate, you can see all the result.

And the fact is, if you run the file directly in terminal window,
everything is OK.

Any suggestions? Should I set something to bypass the buffer?

Best regards

Ling


#include <stdlib.h
#include <stdio.h

int main(int argc, char argv[]) {
int i,j;
printf(“Please enter the number you want to display:”);
scanf("%d",&j);
printf("\n");
for (i= 0 ;i<j;i++)
printf("%d^2= %d\n",i,i
i);
return EXIT_SUCCESS;
}

Hi, Lisa,

Thank you so much! It works. Hope they can fix the problem asap.

Best regards

Ling

Lisa Scanlan wrote:

I was told by the help group that this was a known problem that would be
fixed in a future release. Here is the workaround they gave me (you need to
call it once for each thread that uses stdout):

setvbuf (stdout, NULL, _IOLBF, 0);

Best regards,

Lisa

“Ling Shen” <> ling@ece.concordia.ca> > wrote in message
news:> 3EE101B9.8080607@ece.concordia.ca> …


Hi there,

I found the debug console has some problems. When I use printf() or
cout, the outputs to the concole seemed to be buffered and do not show
immediately, You need to terminal the program to see the result, or need
to print a lot of thing to “push” the result out.

PLS try the small codes below, and set a breakpoint at the line
return. When you debug and run it, it supposed to display “Please enter
the number you want to display” immediately, but, in fact, there is
nothing. If you input “10”, you will get nothing before you resume the
code and let it terminate. And if you input “100”, you can see
something, and the last line will be: 93^2= 8649, then if you resume the
code and let it terminate, you can see all the result.

And the fact is, if you run the file directly in terminal window,
everything is OK.

Any suggestions? Should I set something to bypass the buffer?

Best regards

Ling


#include <stdlib.h
#include <stdio.h

int main(int argc, char argv[]) {
int i,j;
printf(“Please enter the number you want to display:”);
scanf("%d",&j);
printf("\n");
for (i= 0 ;i<j;i++)
printf("%d^2= %d\n",i,i
i);
return EXIT_SUCCESS;
}
\

Lisa Scanlan <~~~lscanlan@ormec.com> wrote:

I was told by the help group that this was a known problem that would be
fixed in a future release. Here is the workaround they gave me (you need to
call it once for each thread that uses stdout):

setvbuf (stdout, NULL, _IOLBF, 0);

Not per thread – once per program that uses stdout. (Make it your
first code line in main() is a good way to do this.)


#include <stdlib.h
#include <stdio.h

int main(int argc, char *argv[]) {
int i,j;

setvbuf (stdout, NULL, _IOLBF, 0);

printf(“Please enter the number you want to display:”);
scanf("%d",&j);
printf("\n");
for (i= 0 ;i<j;i++)
printf("%d^2= %d\n",i,i*i);
return EXIT_SUCCESS;
}

-David

QNX Training Services
http://www.qnx.com/support/training/
Please followup in this newsgroup if you have further questions.

Ling Shen <ling@ece.concordia.ca> wrote:

Hi, Lisa,

Thank you so much! It works. Hope they can fix the problem asap.

This problem, the non-terminal like behaviour of the console, has
been addressed for the 6.3.0 release, but will require a
new target agent to be used.

Thanks,
Thomas

Lisa Scanlan wrote:
I was told by the help group that this was a known problem that would be
fixed in a future release. Here is the workaround they gave me (you need to
call it once for each thread that uses stdout):

setvbuf (stdout, NULL, _IOLBF, 0);

Best regards,

Lisa

“Ling Shen” <> ling@ece.concordia.ca> > wrote in message
news:> 3EE101B9.8080607@ece.concordia.ca> …


Hi there,

I found the debug console has some problems. When I use printf() or
cout, the outputs to the concole seemed to be buffered and do not show
immediately, You need to terminal the program to see the result, or need
to print a lot of thing to “push” the result out.

PLS try the small codes below, and set a breakpoint at the line
return. When you debug and run it, it supposed to display “Please enter
the number you want to display” immediately, but, in fact, there is
nothing. If you input “10”, you will get nothing before you resume the
code and let it terminate. And if you input “100”, you can see
something, and the last line will be: 93^2= 8649, then if you resume the
code and let it terminate, you can see all the result.

And the fact is, if you run the file directly in terminal window,
everything is OK.

Any suggestions? Should I set something to bypass the buffer?

Best regards

Ling


#include <stdlib.h
#include <stdio.h

int main(int argc, char argv[]) {
int i,j;
printf(“Please enter the number you want to display:”);
scanf("%d",&j);
printf("\n");
for (i= 0 ;i<j;i++)
printf("%d^2= %d\n",i,i
i);
return EXIT_SUCCESS;
}

\

Thomas (toe-mah) Fletcher QNX Software Systems
thomasf@qnx.com OS Tools Development Group
(613)-591-0931 http://www.qnx.com/