?? glib-warnings-and-assertions.html
字號:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><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.73.2"><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.9 (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"><link rel="index" href="ix06.html" title="Index of new symbols in 2.8"><link rel="index" href="ix07.html" title="Index of new symbols in 2.10"><link rel="index" href="ix08.html" title="Index of new symbols in 2.12"><link rel="index" href="ix09.html" title="Index of new symbols in 2.14"><link rel="index" href="ix10.html" title="Index of new symbols in 2.16"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><table class="navigation" id="top" 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><tr><td colspan="5" class="shortcuts"><nobr><a href="#id2953625" class="shortcut">Top</a>  |  <a href="#id2953918" class="shortcut">Description</a></nobr></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><a name="id2953625"></a><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 class="link" href="glib-Warnings-and-Assertions.html#g-print">g_print</a> (const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *format, ...);<a class="link" href="glib-Warnings-and-Assertions.html#GPrintFunc">GPrintFunc</a> <a class="link" href="glib-Warnings-and-Assertions.html#g-set-print-handler">g_set_print_handler</a> (<a class="link" href="glib-Warnings-and-Assertions.html#GPrintFunc">GPrintFunc</a> func);void (<a class="link" href="glib-Warnings-and-Assertions.html#GPrintFunc">*GPrintFunc</a>) (const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *string);void <a class="link" href="glib-Warnings-and-Assertions.html#g-printerr">g_printerr</a> (const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *format, ...);<a class="link" href="glib-Warnings-and-Assertions.html#GPrintFunc">GPrintFunc</a> <a class="link" href="glib-Warnings-and-Assertions.html#g-set-printerr-handler">g_set_printerr_handler</a> (<a class="link" href="glib-Warnings-and-Assertions.html#GPrintFunc">GPrintFunc</a> func);#define <a class="link" href="glib-Warnings-and-Assertions.html#g-return-if-fail">g_return_if_fail</a> (expr)#define <a class="link" href="glib-Warnings-and-Assertions.html#g-return-val-if-fail">g_return_val_if_fail</a> (expr,val)#define <a class="link" href="glib-Warnings-and-Assertions.html#g-return-if-reached">g_return_if_reached</a> ()#define <a class="link" href="glib-Warnings-and-Assertions.html#g-return-val-if-reached">g_return_val_if_reached</a> (val)#define <a class="link" href="glib-Warnings-and-Assertions.html#g-warn-if-fail">g_warn_if_fail</a> (expr)#define <a class="link" href="glib-Warnings-and-Assertions.html#g-warn-if-reached">g_warn_if_reached</a> ()void <a class="link" href="glib-Warnings-and-Assertions.html#g-warn-message">g_warn_message</a> (const char *domain, const char *file, int line, const char *func, const char *warnexpr);void <a class="link" href="glib-Warnings-and-Assertions.html#g-on-error-query">g_on_error_query</a> (const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *prg_name);void <a class="link" href="glib-Warnings-and-Assertions.html#g-on-error-stack-trace">g_on_error_stack_trace</a> (const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *prg_name);#define <a class="link" href="glib-Warnings-and-Assertions.html#G-BREAKPOINT:CAPS">G_BREAKPOINT</a> ()</pre></div><div class="refsect1" lang="en"><a name="id2953918"></a><h2>Description</h2><p>These functions provide support for outputting messages.</p><p>The <code class="function">g_return</code> family of macros (<a class="link" href="glib-Warnings-and-Assertions.html#g-return-if-fail"><code class="function">g_return_if_fail()</code></a>, <a class="link" href="glib-Warnings-and-Assertions.html#g-return-val-if-fail"><code class="function">g_return_val_if_fail()</code></a>, <a class="link" href="glib-Warnings-and-Assertions.html#g-return-if-reached"><code class="function">g_return_if_reached()</code></a>, <a class="link" href="glib-Warnings-and-Assertions.html#g-return-val-if-reached"><code class="function">g_return_val_if_reached()</code></a>)should only be used for programming errors, a typical use case ischecking for invalid parameters at the beginning of a public function.They should not be used if you just mean "if (error) return", theyshould only be used if you mean "if (bug in program) return".The program behavior is generally considered undefined after one of these checks fails. They are not intended for normal control flow, only togive a perhaps-helpful warning before giving up. </p></div><div class="refsect1" lang="en"><a name="id2953994"></a><h2>Details</h2><div class="refsect2" lang="en"><a name="id2954004"></a><h3><a name="g-print"></a>g_print ()</h3><a class="indexterm" name="id2954017"></a><pre class="programlisting">void g_print (const <a class="link" 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 class="link" 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 class="link" href="glib-Message-Logging.html#g-log"><code class="function">g_log()</code></a>, or the convenience functions<a class="link" href="glib-Message-Logging.html#g-message"><code class="function">g_message()</code></a>, <a class="link" href="glib-Message-Logging.html#g-warning"><code class="function">g_warning()</code></a> and <a class="link" 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><p><span class="term"><em class="parameter"><code>format</code></em> :</span></p></td><td>the message format. See the <code class="function">printf()</code> documentation.</td></tr><tr><td><p><span class="term"><em class="parameter"><code>...</code></em> :</span></p></td><td>the parameters to insert into the format string.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2954151"></a><h3><a name="g-set-print-handler"></a>g_set_print_handler ()</h3><a class="indexterm" name="id2954165"></a><pre class="programlisting"><a class="link" href="glib-Warnings-and-Assertions.html#GPrintFunc">GPrintFunc</a> g_set_print_handler (<a class="link" href="glib-Warnings-and-Assertions.html#GPrintFunc">GPrintFunc</a> func);</pre><p>Sets the print handler.Any messages passed to <a class="link" 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><p><span class="term"><em class="parameter"><code>func</code></em> :</span></p></td><td>the new print handler.</td></tr><tr><td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td><td>the old print handler.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2954236"></a><h3><a name="GPrintFunc"></a>GPrintFunc ()</h3><a class="indexterm" name="id2954249"></a><pre class="programlisting">void (*GPrintFunc) (const <a class="link" 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><p><span class="term"><em class="parameter"><code>string</code></em> :</span></p></td><td>the message to be output.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2954297"></a><h3><a name="g-printerr"></a>g_printerr ()</h3><a class="indexterm" name="id2954310"></a><pre class="programlisting">void g_printerr (const <a class="link" 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 class="link" href="glib-Warnings-and-Assertions.html#g-printerr"><code class="function">g_printerr()</code></a> should not be used from within libraries. Instead <a class="link" href="glib-Message-Logging.html#g-log"><code class="function">g_log()</code></a> shouldbe used, or the convenience functions <a class="link" href="glib-Message-Logging.html#g-message"><code class="function">g_message()</code></a>, <a class="link" href="glib-Message-Logging.html#g-warning"><code class="function">g_warning()</code></a> and <a class="link" 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><p><span class="term"><em class="parameter"><code>format</code></em> :</span></p></td><td>the message format. See the <code class="function">printf()</code> documentation.</td></tr><tr><td><p><span class="term"><em class="parameter"><code>...</code></em> :</span></p></td><td>the parameters to insert into the format string.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2954440"></a><h3><a name="g-set-printerr-handler"></a>g_set_printerr_handler ()</h3><a class="indexterm" name="id2954453"></a><pre class="programlisting"><a class="link" href="glib-Warnings-and-Assertions.html#GPrintFunc">GPrintFunc</a> g_set_printerr_handler (<a class="link" href="glib-Warnings-and-Assertions.html#GPrintFunc">GPrintFunc</a> func);</pre><p>Sets the handler for printing error messages.Any messages passed to <a class="link" 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><p><span class="term"><em class="parameter"><code>func</code></em> :</span></p></td><td>the new error message handler.</td></tr><tr><td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td><td>the old error message handler.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2954526"></a><h3><a name="g-return-if-fail"></a>g_return_if_fail()</h3><a class="indexterm" name="id2954539"></a><pre class="programlisting">#define g_return_if_fail(expr)</pre><p>Returns from the current function if the expression is not true.If the expression evaluates to <a class="link" href="glib-Standard-Macros.html#FALSE:CAPS"><code class="literal">FALSE</code></a>, a critical message is logged andthe function returns. This can only be used in functions which do not returna value.</p><div class="variablelist"><table border="0">
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -