$Revision: 1666 $
$Date: 2002-06-12 07:19:37 -0400 (Wed, 12 Jun 2002) $
funcsynopsis — The syntax summary for a function definition
funcsynopsis ::= ((funcsynopsisinfo
|funcprototype
)+)
Name | Type | Default |
label | CDATA | None |
A FuncSynopsis
contains the syntax summary of a function prototype
or a set of function prototypes. The content model of this element
was designed specifically to capture the semantics of most C-language
function prototypes (for use in UNIX reference pages).
This is one of the few places where DocBook attempts to model as well
as describe. Using FuncSynopsis
for languages that are
unrelated to C may prove difficult.
For the most part, the processing application is expected to generate all of the parenthesis, semicolons, commas, and so on. required in the rendered synopsis. The exception to this rule is that the spacing and other punctuation inside a parameter that is a pointer to a function must be provided in the source markup.
With sufficient author cooperation, it should be possible to markup a function synopsis with enough clarity so that a processing system can generate either K&R-style or ANSI-style renderings.
VarArgs
The content model of FuncPrototype
is such that you
cannot use VarArgs
in a function prototype in which the
first few parameters to the function are given explicitly before
the variable arguments (generally rendered as an ellipsis).
In other words, the following synopsis cannot be rendered with
VarArgs
:
int printf(char *format, ...)
Instead, you can enclose the ellipsis in a final Parameter
,
like this:
<funcsynopsis> <funcprototype><funcdef>int <function>printf</function></funcdef> <paramdef> <parameter>char *format</parameter> <parameter>...</parameter> </paramdef> </funcprototype> </funcsynopsis>
In DocBook V4.0, the content model fragment beginning with
FuncDef
will be removed from the content
model of FuncSynopsis
. Instead
FuncSynopsis
will become a mixture of
FuncSynopsisInfo
s and FuncPrototype
s.
Future versions of DocBook may provide additional environments for describing the syntax summaries of functions in other programming languages.
These elements contain funcsynopsis:
answer
, appendix
, application
, article
, attribution
, bibliodiv
, bibliography
, bibliomisc
, blockquote
, callout
, caution
, chapter
, citation
, citetitle
, constraintdef
, emphasis
, entry
, example
, figure
, firstterm
, footnote
, foreignphrase
, glossary
, glossdef
, glossdiv
, glosssee
, glossseealso
, glossterm
, important
, index
, indexdiv
, informalexample
, informalfigure
, itemizedlist
, lineannotation
, link
, listitem
, literallayout
, lotentry
, member
, msgaud
, msgexplan
, msgtext
, note
, olink
, orderedlist
, para
, partintro
, phrase
, preface
, procedure
, productname
, programlisting
, qandadiv
, qandaset
, question
, quote
, refentrytitle
, refsect1
, refsect2
, refsect3
, refsection
, refsynopsisdiv
, remark
, revdescription
, screen
, screeninfo
, sect1
, sect2
, sect3
, sect4
, sect5
, section
, seg
, setindex
, sidebar
, simpara
, simplesect
, step
, synopsis
, taskprerequisites
, taskrelated
, tasksummary
, td
, term
, termdef
, th
, tip
, tocback
, tocentry
, tocfront
, ulink
, variablelist
, warning
.
The function max
returns the larger of two integers:
<!DOCTYPE funcsynopsis PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN" "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd"> <funcsynopsis> <funcprototype> <funcdef>int <function>max</function></funcdef> <paramdef>int <parameter>int1</parameter></paramdef> <paramdef>int <parameter>int2</parameter></paramdef> </funcprototype> </funcsynopsis>
int max( | int1, | |
int2) ; |
int | int1; |
int | int2; |
One can imagine a more flexible max
function that takes
any number of integer arguments and returns the largest integer in
the list:
<!DOCTYPE funcsynopsis PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN" "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd"> <funcsynopsis> <funcsynopsisinfo> #include <varargs.h> </funcsynopsisinfo> <funcprototype> <funcdef>int <function>max</function></funcdef> <varargs/> </funcprototype> </funcsynopsis>
#include <varargs.h>
int max( | ...) ; |
The rand
function takes no arguments and returns a
pseudorandom integer between 0 and 231-1:
<!DOCTYPE funcsynopsis PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN" "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd"> <funcsynopsis> <funcprototype> <funcdef>int <function>rand</function></funcdef> <void/> </funcprototype> </funcsynopsis>
int rand( | ) ; |
The qsort
function takes several arguments, including
a pointer to a function (the function that should perform the
comparison between two elements in order to sort them).
<!DOCTYPE funcsynopsis PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN" "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd"> <funcsynopsis> <funcprototype> <funcdef>void <function>qsort</function></funcdef> <paramdef>void *<parameter>dataptr</parameter>[]</paramdef> <paramdef>int <parameter>left</parameter></paramdef> <paramdef>int <parameter>right</parameter></paramdef> <paramdef>int <parameter>(* comp)</parameter> <funcparams>void *, void *</funcparams></paramdef> </funcprototype> </funcsynopsis>
void qsort( | dataptr, | |
left, | ||
right, | ||
(* comp)) ; |
void * | dataptr; |
int | left; |
int | right; |
int | (* comp) |
For additional examples, see also
funcdef
, funcparams
, paramdef
, refentry
, varargs
.