FuncSynopsis

Name

FuncSynopsis -- The syntax summary for a function definition

Synopsis

Content Model

FuncSynopsis ::=
(FuncSynopsisInfo?,
 (FuncPrototype+|
  (FuncDef,
   (Void|VarArgs|ParamDef+))+),
 FuncSynopsisInfo?)

Attributes

Common attributes

Name

Type

Default

LabelCDATANone

Tag Minimization

Both the start- and end-tags are required for this element.

Parameter Entities

%admon.mix;%bookcomponent.content;%component.mix;
%divcomponent.mix;%example.mix;%figure.mix;
%footnote.mix;%glossdef.mix;%indexdivcomponent.mix;
%para.char.mix;%programlisting.content;%qandaset.mix;
%refcomponent.mix;%screen.content;%sidebar.mix;
%synop.class;%tbl.entry.mdl;

Description

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.

Processing expectations

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.

A Note on the Use of 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>

(4.0) Future Changes

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 FuncSynopsisInfos and FuncPrototypes.

Future Changes

Future versions of DocBook may provide additional environments for describing the syntax summaries of functions in other programming languages.

Parents

These elements contain FuncSynopsis: Answer, Appendix, Application, Article, Attribution, BiblioDiv, Bibliography, BiblioMisc, BlockQuote, Callout, Caution, Chapter, Citation, CiteTitle, Comment, Emphasis, entry, Example, Figure, Footnote, ForeignPhrase, Glossary, GlossDef, GlossDiv, GlossSee, GlossSeeAlso, GlossTerm, Important, Index, IndexDiv, InformalExample, InformalFigure, LineAnnotation, Link, ListItem, LiteralLayout, LoTentry, Member, MsgAud, MsgExplan, MsgText, Note, OLink, Para, PartIntro, Phrase, Preface, Procedure, ProductName, ProgramListing, QandADiv, QandASet, Question, Quote, RefEntryTitle, RefSect1, RefSect2, RefSect3, RefSynopsisDiv, Screen, ScreenInfo, Sect1, Sect2, Sect3, Sect4, Sect5, Section, Seg, SetIndex, Sidebar, SimPara, SimpleSect, Step, Synopsis, Term, Tip, ToCback, ToCentry, ToCfront, ULink, Warning.

Children

The following elements occur in FuncSynopsis: FuncDef, FuncPrototype, FuncSynopsisInfo, ParamDef, VarArgs, Void.

In some contexts, the following elements are allowed anywhere: BeginPage, IndexTerm.

Attributes

Label

Label specifies an identifying number or string that may be used in presentation.

See Also

CmdSynopsis, Synopsis

Examples

The function max returns the larger of two integers:

<!DOCTYPE funcsynopsis PUBLIC "-//OASIS//DTD DocBook V3.1//EN">
<funcsynopsis>
<funcprototype>
  <funcdef>int <function>max</function></funcdef>
  <paramdef>int <parameter>int1</parameter></paramdef>
  <paramdef>int <parameter>int2</parameter></paramdef>
</funcprototype>
</funcsynopsis>

int max(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 V3.1//EN">
<funcsynopsis>
<funcsynopsisinfo>
#include &lt;varargs.h&gt;
</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 V3.1//EN">
<funcsynopsis>
<funcprototype>
<funcdef>int <function>rand</function></funcdef>
  <void>
</funcprototype>
</funcsynopsis>

int rand(void);

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 V3.1//EN">
<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(void *dataptr[], int left, int right, int (* comp) (void *, void *));

For additional examples, see also FuncDef, ParamDef, VarArgs.

Copyright © 1999 O'Reilly & Associates, Inc. All rights reserved.