Search code examples
python-sphinxrestructuredtext

How to reference built-in C types with RST?


I'm documenting a C library with Sphinx and RST; I'm hoping to reference some of C's built-in types within the documentation for several functions. For example, I want to reference C's double type.

I do have at the very top of the file some config to make sure the domain is C:

.. default-domain:: c
.. highlight:: c

Referencing :type:`double` or :c:type:`double` within the function definitions does the job of formatting just fine, but I get a warning when building: Unparseable C cross-reference: 'double'. I gather this is because I haven't explicitly defined the type of double like so:

.. c:type:: double

But defining the type means that it will be visible -- and displaying the built-in types of C on my documentation is suboptimal.

Is there a way to use the :type: syntax within my documentation to reference C built-in types without defining them explicitly (or, if I must define them, to hide the definitions)? Or, alternately, is there a way to silence the build warning? Or, as a third option, is it probably just best to use the :code: syntax, and if so, is there a way to make its styling identical to that of the :type: syntax?


Solution

  • At this time you can not declare the built-in C types (at least it is not supposed to work). However, you can style them using the :c:expr: and c:texpr: roles (https://www.sphinx-doc.org/en/master/usage/restructuredtext/domains.html#inline-expressions-and-types).