| DocBook: The Definitive Guide Version 2.0.8 (Alpha)

# funcsynopsis

$Revision: 1.3 $

$Date: 2002/06/12 11:18:11 $

funcsynopsis — The syntax summary for a function definition

## Synopsis

### Content Model

    funcsynopsis ::=
    ((funcsynopsisinfo|funcprototype)+)

### Attributes

Common attributes

Name | Type | Default
label | CDATA | None

## 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>

### 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 `FuncSynopsisInfo`s and `FuncPrototype`s.

### 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`, `constraintdef`, `emphasis`, `entry`, `example`, `figure`, `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`, `term`, `tip`, `tocback`, `tocentry`, `tocfront`, `ulink`, `variablelist`, `warning`.

### Children

The following elements occur in funcsynopsis: `funcprototype`, `funcsynopsisinfo`.

## 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 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 &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 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) `(`void *, void *`)`;

For additional examples, see also `funcdef`, `funcparams`, `paramdef`, `refentry`, `varargs`.

funcprototype |  | funcsynopsisinfo

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