📄 glib-warnings-and-assertions.html
字号:
<html xmlns:cf="http://docbook.sourceforge.net/xmlns/chunkfast/1.0"><head><meta http-equiv="Content-Type" content="text/html; charset=US-ASCII"><title>Message Output and Debugging Functions</title><meta name="generator" content="DocBook XSL Stylesheets V1.69.0"><link rel="start" href="index.html" title="GLib Reference Manual"><link rel="up" href="glib-core.html" title="GLib Core Application Support"><link rel="prev" href="glib-Error-Reporting.html" title="Error Reporting"><link rel="next" href="glib-Message-Logging.html" title="Message Logging"><meta name="generator" content="GTK-Doc V1.4 (XML mode)"><link rel="stylesheet" href="style.css" type="text/css"><link rel="chapter" href="glib.html" title="GLib Overview"><link rel="chapter" href="glib-fundamentals.html" title="GLib Fundamentals"><link rel="chapter" href="glib-core.html" title="GLib Core Application Support"><link rel="chapter" href="glib-utilities.html" title="GLib Utilities"><link rel="chapter" href="glib-data-types.html" title="GLib Data Types"><link rel="chapter" href="tools.html" title="GLib Tools"><link rel="index" href="ix01.html" title="Index"><link rel="index" href="ix02.html" title="Index of deprecated symbols"><link rel="index" href="ix03.html" title="Index of new symbols in 2.2"><link rel="index" href="ix04.html" title="Index of new symbols in 2.4"><link rel="index" href="ix05.html" title="Index of new symbols in 2.6"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><table class="navigation" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2"><tr valign="middle"><td><a accesskey="p" href="glib-Error-Reporting.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></a></td><td><a accesskey="u" href="glib-core.html"><img src="up.png" width="24" height="24" border="0" alt="Up"></a></td><td><a accesskey="h" href="index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></a></td><th width="100%" align="center">GLib Reference Manual</th><td><a accesskey="n" href="glib-Message-Logging.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td></tr></table><div class="refentry" lang="en"><a name="glib-Warnings-and-Assertions"></a><div class="titlepage"></div><div class="refnamediv"><table width="100%"><tr><td valign="top"><h2><span class="refentrytitle">Message Output and Debugging Functions</span></h2><p>Message Output and Debugging Functions — functions to output messages and help debug applications.</p></td><td valign="top" align="right"></td></tr></table></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">#include <glib.h>void <a href="glib-Warnings-and-Assertions.html#g-print">g_print</a> (const <a href="glib-Basic-Types.html#gchar">gchar</a> *format, ...);<a href="glib-Warnings-and-Assertions.html#GPrintFunc">GPrintFunc</a> <a href="glib-Warnings-and-Assertions.html#g-set-print-handler">g_set_print_handler</a> (<a href="glib-Warnings-and-Assertions.html#GPrintFunc">GPrintFunc</a> func);void (<a href="glib-Warnings-and-Assertions.html#GPrintFunc">*GPrintFunc</a>) (const <a href="glib-Basic-Types.html#gchar">gchar</a> *string);void <a href="glib-Warnings-and-Assertions.html#g-printerr">g_printerr</a> (const <a href="glib-Basic-Types.html#gchar">gchar</a> *format, ...);<a href="glib-Warnings-and-Assertions.html#GPrintFunc">GPrintFunc</a> <a href="glib-Warnings-and-Assertions.html#g-set-printerr-handler">g_set_printerr_handler</a> (<a href="glib-Warnings-and-Assertions.html#GPrintFunc">GPrintFunc</a> func);#define <a href="glib-Warnings-and-Assertions.html#g-return-if-fail">g_return_if_fail</a> (expr)#define <a href="glib-Warnings-and-Assertions.html#g-return-val-if-fail">g_return_val_if_fail</a> (expr,val)#define <a href="glib-Warnings-and-Assertions.html#g-return-if-reached">g_return_if_reached</a> ()#define <a href="glib-Warnings-and-Assertions.html#g-return-val-if-reached">g_return_val_if_reached</a> (val)#define <a href="glib-Warnings-and-Assertions.html#g-assert">g_assert</a> (expr)#define <a href="glib-Warnings-and-Assertions.html#g-assert-not-reached">g_assert_not_reached</a> ()void <a href="glib-Warnings-and-Assertions.html#g-on-error-query">g_on_error_query</a> (const <a href="glib-Basic-Types.html#gchar">gchar</a> *prg_name);void <a href="glib-Warnings-and-Assertions.html#g-on-error-stack-trace">g_on_error_stack_trace</a> (const <a href="glib-Basic-Types.html#gchar">gchar</a> *prg_name);#define <a href="glib-Warnings-and-Assertions.html#G-BREAKPOINT:CAPS">G_BREAKPOINT</a> ()</pre></div><div class="refsect1" lang="en"><a name="id2929642"></a><h2>Description</h2><p>These functions provide support for outputting messages.</p></div><div class="refsect1" lang="en"><a name="id2929653"></a><h2>Details</h2><div class="refsect2" lang="en"><a name="id2929659"></a><h3><a name="g-print"></a>g_print ()</h3><a class="indexterm" name="id2929669"></a><pre class="programlisting">void g_print (const <a href="glib-Basic-Types.html#gchar">gchar</a> *format, ...);</pre><p>Outputs a formatted message via the print handler.The default print handler simply outputs the message to stdout.</p><p><a href="glib-Warnings-and-Assertions.html#g-print"><code class="function">g_print()</code></a> should not be used from within libraries for debugging messages,since it may be redirected by applications to special purpose messagewindows or even files.Instead, libraries should use <a href="glib-Message-Logging.html#g-log"><code class="function">g_log()</code></a>, or the convenience functions<a href="glib-Message-Logging.html#g-message"><code class="function">g_message()</code></a>, <a href="glib-Message-Logging.html#g-warning"><code class="function">g_warning()</code></a> and <a href="glib-Message-Logging.html#g-error"><code class="function">g_error()</code></a>.</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>format</code></em> :</span></td><td>the message format. See the <code class="function"><code class="function">printf()</code></code>documentation.</td></tr><tr><td><span class="term"><em class="parameter"><code>...</code></em> :</span></td><td>the parameters to insert into the format string.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2929810"></a><h3><a name="g-set-print-handler"></a>g_set_print_handler ()</h3><a class="indexterm" name="id2929821"></a><pre class="programlisting"><a href="glib-Warnings-and-Assertions.html#GPrintFunc">GPrintFunc</a> g_set_print_handler (<a href="glib-Warnings-and-Assertions.html#GPrintFunc">GPrintFunc</a> func);</pre><p>Sets the print handler.Any messages passed to <a href="glib-Warnings-and-Assertions.html#g-print"><code class="function">g_print()</code></a> will be output via the new handler.The default handler simply outputs the message to stdout.By providing your own handler you can redirect the output, to a GTK+widget or a log file for example.</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>func</code></em> :</span></td><td>the new print handler.</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td>the old print handler.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2929892"></a><h3><a name="GPrintFunc"></a>GPrintFunc ()</h3><a class="indexterm" name="id2929903"></a><pre class="programlisting">void (*GPrintFunc) (const <a href="glib-Basic-Types.html#gchar">gchar</a> *string);</pre><p>Specifies the type of the print handler functions.These are called with the complete formatted string to output.</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>string</code></em> :</span></td><td>the message to be output.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2929951"></a><h3><a name="g-printerr"></a>g_printerr ()</h3><a class="indexterm" name="id2929962"></a><pre class="programlisting">void g_printerr (const <a href="glib-Basic-Types.html#gchar">gchar</a> *format, ...);</pre><p>Outputs a formatted message via the error message handler.The default handler simply outputs the message to stderr.</p><p><a href="glib-Warnings-and-Assertions.html#g-printerr"><code class="function">g_printerr()</code></a> should not be used from within libraries. Instead <a href="glib-Message-Logging.html#g-log"><code class="function">g_log()</code></a> shouldbe used, or the convenience functions <a href="glib-Message-Logging.html#g-message"><code class="function">g_message()</code></a>, <a href="glib-Message-Logging.html#g-warning"><code class="function">g_warning()</code></a> and <a href="glib-Message-Logging.html#g-error"><code class="function">g_error()</code></a>.</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>format</code></em> :</span></td><td>the message format. See the <code class="function"><code class="function">printf()</code></code>documentation.</td></tr><tr><td><span class="term"><em class="parameter"><code>...</code></em> :</span></td><td>the parameters to insert into the format string.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2930094"></a><h3><a name="g-set-printerr-handler"></a>g_set_printerr_handler ()</h3><a class="indexterm" name="id2930106"></a><pre class="programlisting"><a href="glib-Warnings-and-Assertions.html#GPrintFunc">GPrintFunc</a> g_set_printerr_handler (<a href="glib-Warnings-and-Assertions.html#GPrintFunc">GPrintFunc</a> func);</pre><p>Sets the handler for printing error messages.Any messages passed to <a href="glib-Warnings-and-Assertions.html#g-printerr"><code class="function">g_printerr()</code></a> will be output via the new handler.The default handler simply outputs the message to stderr.By providing your own handler you can redirect the output, to a GTK+widget or a log file for example.</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>func</code></em> :</span></td><td>the new error message handler.</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td>the old error message handler.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2930178"></a><h3><a name="g-return-if-fail"></a>g_return_if_fail()</h3><a class="indexterm" name="id2930188"></a><pre class="programlisting">#define g_return_if_fail(expr)</pre>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -