Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Here is a C code


C++
{ // message block
        char *message = "SYSTEM_STATE_IDLE  ";
        OpenGL_text(message, -1, -1, 0);
        glFlush(); // needed
        int test_count = 0;
        printf("\n test count %i state %s @function  %s @line %i ", test_count++, message,__FUNCTION__,__LINE__);
        printf("\n test count %i state %s @function  %s @line %i ", test_count++, message,__FUNCTION__,__LINE__);
        printf("\n test count %i state %s @function  %s @line %i ", test_count++, message,__FUNCTION__,__LINE__);
        printf("\n test count %i state %s @function  %s @line %i ", test_count++, message,__FUNCTION__,__LINE__);

        glFlush(); // needed ??
    } // message block



The output to OpenGL (screen) is correct, the tracking printf is not.

And here is the incorrect output, assuming printf outputs to standard I/O.

test count 0 state SYSTEM_STATE_IDLE   @function  OpenGL_SystemState @line 4961 
 test count 1 state SYSTEM_STATE_IDLE   @function  OpenGL_SystemState @line 4962 
 test count 2 state SYSTEM_STATE_IDLE   @function  OpenGL_SystemState @line 4963 

Where is count #3 ??

What I have tried:

I am using multiple printf because when I used only one there is NO output at all.
Posted
Updated 8-May-20 5:53am

1 solution

Quote:
Where is count #3 ??

Try
C++
int test_count = 0;
printf("\n test count %i state %s @function  %s @line %i ", test_count++, message,__FUNCTION__,__LINE__);
printf("\n test count %i state %s @function  %s @line %i ", test_count++, message,__FUNCTION__,__LINE__);
printf("\n test count %i state %s @function  %s @line %i ", test_count++, message,__FUNCTION__,__LINE__);
printf("\n test count %i state %s @function  %s @line %i ", test_count++, message,__FUNCTION__,__LINE__);
printf("\n");
 
Share this answer
 
Comments
k5054 8-May-20 12:02pm    
or fflush(stdout) if you don't want to move the cursor to a new line. I'd also say maybe use fputs(stdout, "\n"), so as not to incur the overhead of printf if you don't need to, but I've seen compilers optimize that out for at least 15 years, so its really a matter of taste.
Vaclav_ 8-May-20 17:46pm    
OpenGL has a "feature" glFlush described as " force OpenGL to complete the previous code IMMEDIATELY" I am not interested in finding out why , but with current experience with printf and a suggestion to use fflush stdout it looks as this "flush stdout " has similar function. So if this is just another version of cout /cerr lacking synchronization with main process I guess "...And that's the way it is..." (W,Cronkite )
Vaclav_ 10-May-20 11:44am    
Sorry folks, but the question was "why not all printf are executed?" . I did not spell it out correctly. It is not question of clearing / flushing, but question is why is it not executed in first place. "I am using multiple printf because when I used only one there is NO output at all."
Patrice T 10-May-20 12:07pm    
Use Improve question to update your question.
So that everyone can pay attention to this information.
Vaclav_ 10-May-20 12:36pm    
So me admitting that I did not post it the way people will interpret it as " why is the printf not executed" is my fault. Sorry , it is not my fault if people do not read REQUIRED " what did you try " unless I post "I did ask Mrs Google..." Give me a break. I do not ask to read in-between line, but (for) simple analysis....

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900