📄 ref.if-define.html
字号:
<!-- Copyright (C) 2003 Red Hat, Inc. --><!-- This material may be distributed only subject to the terms --><!-- and conditions set forth in the Open Publication License, v1.0 --><!-- or later (the latest version is presently available at --><!-- http://www.opencontent.org/openpub/). --><!-- Distribution of the work or derivative of the work in any --><!-- standard (paper) book form is prohibited unless prior --><!-- permission is obtained from the copyright holder. --><HTML><HEAD><TITLE>if_define</TITLE><meta name="MSSmartTagsPreventParsing" content="TRUE"><METANAME="GENERATOR"CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+"><LINKREL="HOME"TITLE="The eCos Component Writer's Guide"HREF="cdl-guide.html"><LINKREL="UP"TITLE="CDL Language Specification"HREF="reference.html"><LINKREL="PREVIOUS"TITLE="hardware"HREF="ref.hardware.html"><LINKREL="NEXT"TITLE="implements"HREF="ref.implements.html"></HEAD><BODYCLASS="REFENTRY"BGCOLOR="#FFFFFF"TEXT="#000000"LINK="#0000FF"VLINK="#840084"ALINK="#0000FF"><DIVCLASS="NAVHEADER"><TABLESUMMARY="Header navigation table"WIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><THCOLSPAN="3"ALIGN="center">The <SPANCLASS="APPLICATION">eCos</SPAN> Component Writer's Guide</TH></TR><TR><TDWIDTH="10%"ALIGN="left"VALIGN="bottom"><AHREF="ref.hardware.html"ACCESSKEY="P">Prev</A></TD><TDWIDTH="80%"ALIGN="center"VALIGN="bottom"></TD><TDWIDTH="10%"ALIGN="right"VALIGN="bottom"><AHREF="ref.implements.html"ACCESSKEY="N">Next</A></TD></TR></TABLE><HRALIGN="LEFT"WIDTH="100%"></DIV><H1><ANAME="REF.IF-DEFINE"><SPANCLASS="PROPERTY">if_define</SPAN></H1><DIVCLASS="REFNAMEDIV"><ANAME="AEN4442"></A><H2>Name</H2>Property <SPANCLASS="PROPERTY">if_define</SPAN> -- Output a common preprocessor construct to a configurationheader file.</DIV><DIVCLASS="REFSYNOPSISDIV"><ANAME="AEN4446"><H2>Synopsis</H2><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="SYNOPSIS">cdl_option <name> { if_define [-file=<filename>] <symbol1> <symbol2> …}</PRE></TD></TR></TABLE></DIV><DIVCLASS="REFSECT1"><ANAME="AEN4448"></A><H2>Description</H2><P>The purpose of the <SPANCLASS="PROPERTY">if_define</SPAN> property is best explained by anexample. Suppose you want finer-grained control over assertions, sayon a per-package or even a per-file basis rather than globally. Theassertion macros can be defined by an exported header file in aninfrastructure package, using code like the following:</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">#ifdef CYGDBG_USE_ASSERTS# define CYG_ASSERT( _bool_, _msg_ ) \ CYG_MACRO_START \ if ( ! ( _bool_ ) ) \ CYG_ASSERT_DOCALL( _msg_ ); \ CYG_MACRO_END#else# define CYG_ASSERT( _bool_, _msg_ ) CYG_EMPTY_STATEMENT#endif</PRE></TD></TR></TABLE><P>Assuming this header file is <TTCLASS="LITERAL">#include'd</TT> directly orindirectly by any code which may need to be built with assertionsenabled, the challenge is now to control whether or not<TTCLASS="VARNAME">CYGDBG_USE_ASSERTS</TT> is defined for any given sourcefile. This is the purpose of the <SPANCLASS="PROPERTY">if_define</SPAN> property:</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">cdl_option CYGDBG_KERNEL_USE_ASSERTS { … if_define CYGSRC_KERNEL CYGDBG_USE_ASSERTS requires CYGDBG_INFRA_ASSERTION_SUPPORT}</PRE></TD></TR></TABLE><P>If this option is active and enabled then the kernel's configurationheader file would end up containing the following:</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">#ifdef CYGSRC_KERNEL# define CYGDBG_USE_ASSERTS 1#endif</PRE></TD></TR></TABLE><P>Kernel source code can now begin with the following construct:</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">#define CYGSRC_KERNEL 1#include <pkgconf/kernel.h>#include <cyg/infra/cyg_ass.h></PRE></TD></TR></TABLE><P>The configuration option only affects kernel source code, assumingnothing else <TTCLASS="LITERAL">#define's</TT> the symbol<TTCLASS="VARNAME">CYGSRC_KERNEL</TT>. If the per-package assertion optionis disabled then <TTCLASS="VARNAME">CYGDBG_USE_ASSERTS</TT> will not getdefined. If the option is enabled then<TTCLASS="VARNAME">CYGDBG_USE_ASSERTS</TT> will get defined and assertionswill be enabled for the kernel sources. It is possible to use the samemechanism for other facilities such as tracing, and to apply it at afiner grain such as individual source files by having multiple optionswith <SPANCLASS="PROPERTY">if_define</SPAN> properties and multiple symbols such as<TTCLASS="VARNAME">CYGSRC_KERNEL_SCHED_BITMAP_CXX</TT>.</P><P>The <SPANCLASS="PROPERTY">if_define</SPAN> property takes two arguments, both of which must bevalid C preprocessor symbols. If the current option is active andenabled then three lines will be output to the configuration headerfile:</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">#ifdef <symbol1># define <symbol2>#endif</PRE></TD></TR></TABLE><P>If the option is inactive or disabled then these lines will not beoutput. By default the current package's configuration header filewill be used, but it is possible to specify an alternative destinationusing a <TTCLASS="LITERAL">-file</TT> option. At present the onlylegitimate alternative destination is <TTCLASS="LITERAL">system.h</TT>, theglobal configuration header. <SPANCLASS="PROPERTY">if_define</SPAN> processing happens inaddition to, not instead of, the normal <TTCLASS="LITERAL">#define</TT>processing or the handling of other header-file related properties.</P><DIVCLASS="NOTE"><BLOCKQUOTECLASS="NOTE"><P><B>Note: </B>The infrastructure in the current <SPANCLASS="APPLICATION">eCos</SPAN> release does not yet workthis way. In future it may do so, and the intention is that suitableconfiguration options get generated semi-automatically by theconfiguration system rather than having to be defined explicitly.</P></BLOCKQUOTE></DIV><DIVCLASS="TIP"><BLOCKQUOTECLASS="TIP"><P><B>Tip: </B>As an alternative to changing the configuration, updating the buildtree, and so on, it is possible to enable assertions by editing asource file directly, for example:</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">#define CYGSRC_KERNEL 1#define CYGDBG_USE_ASSERTS 1#include <pkgconf/kernel.h>#include <cyg/infra/cyg_ass.h></PRE></TD></TR></TABLE><P>The assertion header file does not care whether<TTCLASS="VARNAME">CYGDBG_USE_ASSERTS</TT> is <TTCLASS="LITERAL">#define'd</TT>via a configuration option or by explicit code. This technique can beuseful to component writers when debugging their source code, althoughcare has to be taken to remove any such <TTCLASS="LITERAL">#define's</TT>later on.</P></BLOCKQUOTE></DIV></DIV><DIVCLASS="REFSECT1"><ANAME="AEN4487"></A><H2>Example</H2><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">cdl_option CYGDBG_KERNEL_USE_ASSERTS { display "Assertions in the kernel package" … if_define CYGSRC_KERNEL CYGDBG_USE_ASSERTS requires CYGDBG_INFRA_ASSERTION_SUPPORT}</PRE></TD></TR></TABLE></DIV><DIVCLASS="REFSECT1"><ANAME="AEN4490"></A><H2>See Also</H2><P>Properties <AHREF="ref.define.html"><SPANCLASS="PROPERTY">define</SPAN></A>,<AHREF="ref.define-format.html"><SPANCLASS="PROPERTY">define_format</SPAN></A>,<AHREF="ref.define-header.html"><SPANCLASS="PROPERTY">define_header</SPAN></A>,<AHREF="ref.define-proc.html"><SPANCLASS="PROPERTY">define_proc</SPAN></A> and<AHREF="ref.no-define.html"><SPANCLASS="PROPERTY">no_define</SPAN></A>.</P></DIV><DIVCLASS="NAVFOOTER"><HRALIGN="LEFT"WIDTH="100%"><TABLESUMMARY="Footer navigation table"WIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top"><AHREF="ref.hardware.html"ACCESSKEY="P">Prev</A></TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="cdl-guide.html"ACCESSKEY="H">Home</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top"><AHREF="ref.implements.html"ACCESSKEY="N">Next</A></TD></TR><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top"><SPANCLASS="PROPERTY">hardware</SPAN></TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="reference.html"ACCESSKEY="U">Up</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top"><SPANCLASS="PROPERTY">implements</SPAN></TD></TR></TABLE></DIV></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -