Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3312986
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:03:43+00:00 2026-05-17T22:03:43+00:00

Right when I am at fflush(stdout) and I break there in GDB, can I

  • 0

Right when I am at fflush(stdout) and I break there in GDB, can I know what is there in stdout before I actually print it?

How can I know what is there in stdout at any point in time?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T22:03:44+00:00Added an answer on May 17, 2026 at 10:03 pm

    You almost certainly can, but you probably shouldn’t. The standard requires only that FILE be a type that is useful to the implementation to identify an open file and whatever state is required to implement the semantics of the various functions that operate on streams.

    I’d generally agree with other posters that fflush() is a reliable way to know what you actually wrote to the file.

    However, if you have lost track of what parts of your code might be writing to a stream, then it can occasionally be useful to watch the stream in action and catch it changing.

    In practice, FILE is a typedef for a struct that is declared by your implementation in the header file stdio.h (often named struct _iobuf). Although a typical implementation only lightly documents its members, a typical implementation also implements putchar() and some of its friends as macros that are also found in stdio.h. That, combined with the likely availability of sources for the C runtime library of any toolchain you are likely to be using with gdb, gets you all the information you need to peek under the hood.

    The stdio.h provided in MinGW GCC 3.4.5 implements FILE as follows:

    typedef struct _iobuf
    {
        char*   _ptr;
        int _cnt;
        char*   _base;
        int _flag;
        int _file;
        int _charbuf;
        int _bufsiz;
        char*   _tmpfname;
    } FILE;
    
    // oversimplify declaration of _iob[] here for clarity:
    extern FILE _iob[FOPEN_MAX];    /* An array of FILE imported from DLL. */
    //...
    #define STDIN_FILENO    0
    #define STDOUT_FILENO   1
    #define STDERR_FILENO   2
    #define stdin   (&_iob[STDIN_FILENO])
    #define stdout  (&_iob[STDOUT_FILENO])
    #define stderr  (&_iob[STDERR_FILENO])
    

    and implements putchar() as an inline function taking advantage of a GCC extension to C:

    __CRT_INLINE int __cdecl __MINGW_NOTHROW putchar(int __c)
    {
      return (--stdout->_cnt >= 0)
        ?  (int) (unsigned char) (*stdout->_ptr++ = (char)__c)
        :  _flsbuf (__c, stdout);}
    

    From this you can tell that the end of the buffer is pointed to by the member _ptr, and infer that the only other char * in struct _iobuf (_base) is pointing to the beginning of the buffer. The member _cnt is clearly the count of unused characters remaining in the buffer. The function _flsbuf() must take the first character that didn’t fit and put it at the beginning of the buffer after it wrote the current buffer content to the file and restored the _cnt field.

    So, if you watch stdout->_base and BUFSIZ - stdout->_cnt you would, for this implementation, have a display of how much and what is in the current buffer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Right now I currently using transactional replication with updatable subscription. Is there any ways
Right now I am using std::pair to represent a 2d point in c++. However,
Right now I can use this URL to request a Google Static Maps image
I'm starting a new project, trying to do things right this time(so more than
My code won't run the last line right before exit; and I have no
How can I create a 3 column CSS layout, with the left and right
I can't launch my simple Fixture, I installed the bundle in the right way
I don't know exactly how threads work, but I guess i'm doing it right.
I'd like to right align this gridview so that it's flush against the right
Right now I have this SQL query which is valid but always times out:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.