I would like to look at the int putchar(char) implementation int putchar(char) , but I just can not find it. I would be grateful for the answer.

  • one
    Somewhere here git.musl-libc.org/cgit/musl/tree/src/stdio should be (if not defined as a macro in stdio.h or other .h files connected to it) - avp
  • Thanks, I will look! but I have a feeling that it is really defined by a macro - Eric
  • Implementations may be different. For example glibc google here . - αλεχολυτ
  • Judging by /usr/include/stdio.h:extern int putchar (int __c); Linux is definitely not a macro. - avp

1 answer 1

Let me note that there is no such function - int putchar(char) - there is int putchar(int) .

In Open Watcom, in fact, it is (I will not write here all these modifiers and so on ...):

 int putchar(int c) { return fputc(c, stdout); } 

Well, if you want to look at fputc , then welcome, I don’t want to break my head or feet :)

 _WCRTLINK int fputc( int c, FILE *fp ) { int flags; _ValidFile( fp, EOF ); _AccessFile( fp ); /*** Deal with stream orientation ***/ ORIENT_STREAM(fp,EOF); if( !(fp->_flag & _WRITE) ) { __set_errno( EBADF ); fp->_flag |= _SFERR; _ReleaseFile( fp ); return( EOF ); } if( _FP_BASE(fp) == NULL ) { __ioalloc( fp ); } flags = _IONBF; if( c == '\n' ) { flags = _IONBF | _IOLBF; #ifndef __UNIX__ if( !(fp->_flag & _BINARY) ) { fp->_flag |= _DIRTY; *fp->_ptr = '\r'; /* '\n' -> '\r''\n' */ fp->_ptr++; fp->_cnt++; if( fp->_cnt == fp->_bufsize ) { if( __flush( fp ) ) { _ReleaseFile( fp ); return( EOF ); } } } #endif } fp->_flag |= _DIRTY; *fp->_ptr = c; fp->_ptr++; fp->_cnt++; if( (fp->_flag & flags) || (fp->_cnt == fp->_bufsize) ) { if( __flush( fp ) ) { _ReleaseFile( fp ); return( EOF ); } } _ReleaseFile( fp ); return( (UCHAR_TYPE)c ); }