📄 ref.default-value.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>default_value</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="compile"HREF="ref.compile.html"><LINKREL="NEXT"TITLE="define"HREF="ref.define.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.compile.html"ACCESSKEY="P">Prev</A></TD><TDWIDTH="80%"ALIGN="center"VALIGN="bottom"></TD><TDWIDTH="10%"ALIGN="right"VALIGN="bottom"><AHREF="ref.define.html"ACCESSKEY="N">Next</A></TD></TR></TABLE><HRALIGN="LEFT"WIDTH="100%"></DIV><H1><ANAME="REF.DEFAULT-VALUE"><SPANCLASS="PROPERTY">default_value</SPAN></H1><DIVCLASS="REFNAMEDIV"><ANAME="AEN3887"></A><H2>Name</H2>Property <SPANCLASS="PROPERTY">default_value</SPAN> -- Provide a default value for this option using a CDL expression.</DIV><DIVCLASS="REFSYNOPSISDIV"><ANAME="AEN3891"><H2>Synopsis</H2><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="SYNOPSIS">cdl_option <name> { default_value <expression> …}</PRE></TD></TR></TABLE></DIV><DIVCLASS="REFSECT1"><ANAME="AEN3893"></A><H2>Description</H2><P>The <SPANCLASS="PROPERTY">default_value</SPAN> property allows the initial value of aconfiguration option to depend on other configuration options. Thearguments to the property should be a <SPANCLASS="APPLICATION">CDL</SPAN> expression, see<AHREF="language.values.html#LANGUAGE.EXPRESSION">the Section called <I>Ordinary Expressions</I> in Chapter 3</A> for the syntactic details.In many cases a simple constant value will suffice, for example:</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">cdl_component CYGPKG_KERNEL_EXCEPTIONS { … default_value 1 cdl_option CYGSEM_KERNEL_EXCEPTIONS_DECODE { … default_value 0 }}</PRE></TD></TR></TABLE><P>However it is also possible for an option's default value to depend onother options. For example the common HAL package provides somesupport functions that are needed by the <SPANCLASS="APPLICATION">eCos</SPAN> kernel, but areunlikely to be useful if the kernel is not being used. Thisrelationship can be expressed using:</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">cdl_option CYGFUN_HAL_COMMON_KERNEL_SUPPORT { ... default_value CYGPKG_KERNEL}</PRE></TD></TR></TABLE><P>If the kernel is loaded then this HAL option is automatically enabled,although the user can still disable it explicitly should this provenecessary. If the kernel is not loaded then the option is disabled,although it can still be enabled by the user if desired.<SPANCLASS="PROPERTY">default_value</SPAN> expressions can be more complicated than this ifappropriate, and provide a very powerful facility for componentwriters who want their code to “just do the right thing”in a wide variety of configurations.</P><P>The <SPANCLASS="APPLICATION">CDL</SPAN> configuration system evaluates the <SPANCLASS="PROPERTY">default_value</SPAN>expression when the current package is loaded and whenever there is achange to any other option referenced in the expression. The resultdepends on the option's flavor:</P><P></P><DIVCLASS="VARIABLELIST"><DL><DT><TTCLASS="LITERAL">flavor none</TT></DT><DD><P>Options with this flavor have no value, so the <SPANCLASS="PROPERTY">default_value</SPAN>property is not applicable.</P></DD><DT><TTCLASS="LITERAL">flavor bool</TT></DT><DD><P>If the expression evaluates to a non-zero result the option isenabled by default, otherwise it is disabled.</P></DD><DT><TTCLASS="LITERAL">flavor booldata</TT></DT><DD><P>If the result of evaluating the expression is zero then the option isdisabled, otherwise the option is enabled and its value is the result.</P></DD><DT><TTCLASS="LITERAL">flavor data</TT></DT><DD><P>The default value of the option is the result of evaluating theexpression.</P></DD></DL></DIV><P>A <TTCLASS="LITERAL">cdl_option</TT> or other entity can have at most one <SPANCLASS="PROPERTY">default_value</SPAN>property, and it is illegal to have both a <SPANCLASS="PROPERTY">calculated</SPAN> and a<SPANCLASS="PROPERTY">default_value</SPAN> property in one body. If an option does not haveeither a <SPANCLASS="PROPERTY">default_value</SPAN> or a <SPANCLASS="PROPERTY">calculated</SPAN> property and it does nothave the flavor <TTCLASS="LITERAL">none</TT> then the configuration toolswill assume a default value expression of <TTCLASS="LITERAL">0</TT>.</P><P>On occasion it is useful to have a configuration option<TTCLASS="LITERAL">A</TT> which has both a <SPANCLASS="PROPERTY">requires</SPAN> constraint on someother option <TTCLASS="LITERAL">B</TT> and a <SPANCLASS="PROPERTY">default_value</SPAN> expression of<TTCLASS="LITERAL">B</TT>. If option <TTCLASS="LITERAL">B</TT> is not enabledthen <TTCLASS="LITERAL">A</TT> will also be disabled by default and noconflict arises. If <TTCLASS="LITERAL">B</TT> is enabled then<TTCLASS="LITERAL">A</TT> also becomes enabled and again no conflictarises. If a user attempts to enable <TTCLASS="LITERAL">B</TT> but not<TTCLASS="LITERAL">A</TT> then there will be a conflict. Users should beable to deduce that the two options are closely interlinked and shouldnot be manipulated independently except in very unusual circumstances.</P><DIVCLASS="TIP"><BLOCKQUOTECLASS="TIP"><P><B>Tip: </B>If the first entry in a <SPANCLASS="PROPERTY">default_value</SPAN> expression is a negativenumber, for example <TTCLASS="LITERAL">default_value -1</TT> then thiscan be misinterpreted as an option instead of as part of theexpression. Currently the <SPANCLASS="PROPERTY">default_value</SPAN> property does not take anyoptions, but this may change in future. Option processing halts at thesequence <TTCLASS="LITERAL">--</TT>, so the desired value can be expressedsafely using<TTCLASS="LITERAL">default_value -- -1</TT></P></BLOCKQUOTE></DIV><DIVCLASS="NOTE"><BLOCKQUOTECLASS="NOTE"><P><B>Note: </B>In many cases it would be useful to calculate default values usingsome global preferences, for example:</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">cdl_option CYGIMP_LIBC_STRING_PREFER_SMALL_TO_FAST { … default_value CYGGLO_CODESIZE > CYGGLO_SPEED}</PRE></TD></TR></TABLE><P>Such global preference options do not yet exist, but are likely to beadded in a future version.</P></BLOCKQUOTE></DIV><DIVCLASS="NOTE"><BLOCKQUOTECLASS="NOTE"><P><B>Note: </B>For options with the booldata flavor the current syntax does not allowthe default values of the enabled flag and the value to be controlledseparately. Functionality to permit this may be added in a futurerelease.</P></BLOCKQUOTE></DIV></DIV><DIVCLASS="REFSECT1"><ANAME="AEN3964"></A><H2>Example</H2><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">cdl_option CYGDBG_HAL_DEBUG_GDB_THREAD_SUPPORT { display "Include GDB multi-threading debug support" requires CYGDBG_KERNEL_DEBUG_GDB_THREAD_SUPPORT default_value CYGDBG_KERNEL_DEBUG_GDB_THREAD_SUPPORT description " This option enables some extra HAL code which is needed to support multi-threaded source level debugging."}</PRE></TD></TR></TABLE></DIV><DIVCLASS="REFSECT1"><ANAME="AEN3967"></A><H2>See Also</H2><P>Properties <AHREF="ref.calculated.html"><SPANCLASS="PROPERTY">calculated</SPAN></A>,<AHREF="ref.flavor.html"><SPANCLASS="PROPERTY">flavor</SPAN></A> and<AHREF="ref.legal-values.html"><SPANCLASS="PROPERTY">legal_values</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.compile.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.define.html"ACCESSKEY="N">Next</A></TD></TR><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top"><SPANCLASS="PROPERTY">compile</SPAN></TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="reference.html"ACCESSKEY="U">Up</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top"><SPANCLASS="PROPERTY">define</SPAN></TD></TR></TABLE></DIV></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -