ferr.c

来自「一个c语言写做的编译器的源码」· C语言 代码 · 共 34 行

C
34
字号
/*@A (C) 1992 Allen I. Holub                                                */
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <tools/debug.h>
#include <tools/l.h>

/* Note that ferr() is typed as int, even though it usually doesn't return,
 * because it's occasionally useful to use it inside a conditional expression
 * where a type will be required.
 */

ANSI( int  ferr( char *fmt, ... )	)
KnR ( int  ferr( fmt            )	)
KnR ( char *fmt;			)
{
  D(	void		(**ret_addr_p)(); )
	va_list	  	args;
UNIX(   extern int	fputc();     )

	va_start( args, fmt );

ANSI(	if( fmt ) prnt   ( (int(*)(int,...))fputc, stderr, fmt, args ); )
UNIX(	if( fmt ) prnt   ( (int(*)(       ))fputc, stderr, fmt, args ); )
	else	  perror ( va_arg(args, char* )     );

  D(	ret_addr_p  = (void (**)()) &fmt ;				  )
  D(	fprintf(stderr, "\n\t--ferr() Called from %p\n", ret_addr_p[-2]); )

	va_end( args );
	exit( on_ferr() );
	BCC( return 0; ) 	/* Keep the compiler happy */
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?