.. _CLangOverview:

.. raw:: html

   <script>ODSA.SETTINGS.DISP_MOD_COMP = true;ODSA.SETTINGS.MODULE_NAME = "CLangOverview";ODSA.SETTINGS.MODULE_LONG_NAME = "C Language Reintroduction";ODSA.SETTINGS.MODULE_CHAPTER = "Appendix A"; ODSA.SETTINGS.BUILD_DATE = "2021-06-01 12:51:47"; ODSA.SETTINGS.BUILD_CMAP = false;JSAV_OPTIONS['lang']='en';JSAV_EXERCISE_OPTIONS['code']='java';</script>


.. |--| unicode:: U+2013   .. en dash
.. |---| unicode:: U+2014  .. em dash, trimming surrounding whitespace
   :trim:


.. This file is part of the OpenCSF eTextbook project. It was
.. auto-generated by scripts from the OpenDSA eTextbook project.
.. See https://OpenCSF.org for more details. OpenCSF is distributed
.. under a Creative Commons Attribution-NonCommercial 4.0 International
.. License (see http://creativecommons.org/licenses/by-nc/4.0/),
.. Copyright (c) 2019-2021 by Michael S. Kirkpatrick. OpenDSA is
.. distributed under an MIT open source license, Copyright (c) 2012-2021
.. by the OpenDSA Project Contributors.

.. avmetadata::
   :author: Michael S. Kirkpatrick
   :requires:
   :satisfies: C Language Overview
   :topic: C

C Language Reintroduction
=========================

.. raw:: html

    <blockquote class="blockquote text-center">
        <p>“Program testing can be used to show the presence of bugs, but never to show their absence!”
        <footer class="blockquote-footer">Edsger Dijkstra</footer>
    </blockquote>

This book assumes some prior experience with the C programming language. However, the way that C is
taught as a programming language and how it is used in the systems world are not always the same. As
a simple example, consider the following trivial example of C code:

.. codeinclude:: CLang/MaxSize.c

In many examples of systems code, this type declaration is too vague to be safe. Specifically,
according to the C language specification, **there is no fixed size for the** ``int`` **type**. While an
``int`` can often be assumed (on modern laptops, desktops, or server machines) to be four bytes in
size, it doesn't have to be. On some embedded systems, for instance, an ``int`` is only two bytes in
size. This declaration would then be a problem, because the value **65,536 cannot be represented as
a two-byte signed integer** (which range from -32,768 to 32,767). Consequently, systems programmers
typically use more explicit types that clearly indicate the exact size, such as ``uint32_t``
(unsigned 32-bit integer). 

This Appendix is intended as a re-introduction to the C language as used by this text. It is not
intended as a complete introduction for readers who have never used C before. For instance, there is
no coverage here of standard control structures, such as loops or conditional statements. We also do
not cover file-related functions (such as ``fopen()``) that use pointers to FILE instances, as these
functions are oriented toward ASCII-formatted text files; systems programming typically involves
working with binary-formatted data instead. Instead, this Appendix focuses on intermediate or
advanced features of C that are commonly used in systems programming. We start this Appendix with a
discussion of how to consult documentation and debugging, as these are critical skills for systems
programming.


