Changeset ba3f265 in rtems-docs


Ignore:
Timestamp:
Jul 24, 2020, 5:10:51 AM (2 weeks ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
fd2fc50
Parents:
7ee5a7b
Message:

eng: Add recommendations for attributes

Fix formatting.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • eng/coding-conventions.rst

    r7ee5a7b rba3f265  
    2222* Start each file with a brief description followed by a license.
    2323  See `Boilerplate File Header <https://devel.rtems.org/wiki/Developer/Coding/Boilerplate_File_Header>`_..
    24 * Use /* */ comments.
     24* Use ``/* */`` comments.
    2525* Use comments wisely within function bodies, to explain
    2626  or draw attention without being verbose.
     
    4949
    5050* Use C99.
     51
    5152* Treat warnings as errors: eliminate them.
     53
    5254* Favor C, but when assembly language is required use inline
    5355  assembly if possible.
     56
    5457* Do not use compiler extensions.
    55 * Use the RTEMS_macros defined in score/basedefs.h for abstracting
    56   compiler-specific features.
     58
     59* Use the RTEMS macros defined in <rtems/score/basedefs.h> for abstracting
     60  compiler-specific features.  For using attributes see the
     61  `GCC attribute syntax <https://gcc.gnu.org/onlinedocs/gcc/Attribute-Syntax.html#Attribute-Syntax>`_.
     62  Prefer to place attributes in front of the declarator.  Try to be in line
     63  with
     64  `C++11 attributes <https://en.cppreference.com/w/cpp/language/attributes>`_
     65  and C11 keywords such as
     66  `_Noreturn <https://en.cppreference.com/w/c/language/_Noreturn>`_.
     67
    5768* Use NULL for the null pointer, and prefer to use explicit
    5869  checks against NULL, e.g.,
     
    6172
    6273      if ( ptr != NULL )
     74
    6375  instead of
    6476
     
    6678
    6779      if ( !ptr )
     80
    6881* Use explicit checks for bits in variables.
     82
    6983   * Example 1: Use
     84
    7085      .. code-block:: c
    7186
    7287           if ( XBITS == (var & XBITS) )
     88
    7389     to check for a set of defined bits.
     90
    7491   * Example 2: Use
     92
    7593      .. code-block:: c
    7694
    7795          if ( (var & X_FLAGS) != 0) )
     96
    7897     instead of
     98
    7999      .. code-block:: c
    80100
    81101          if ( !!(var & X_FLAGS) )
     102
    82103     to check for at least 1 defined bit in a set.
    83 * Use '(void) unused;' to mark unused parameters and set-but-unused
     104
     105* Use ``(void) unused;`` to mark unused parameters and set-but-unused
    84106  variables immediately after being set.
     107
    85108* Do not put function prototypes in C source files, any global functions
    86109  should have a prototype in a header file and any private function
    87110  should be declared static.
     111
    88112* Declare global variables in exactly one header file.
    89113  Define global variables in at most one source file.
     
    92116  compiler checks the declaration and definition and that
    93117  the header file is self-contained.
     118
    94119* Do not cast arguments to any printf() or printk() variant.
    95120  Use <inttypes.h> PRI constants for the types supported there.
     
    97122  have PRI constants defined there. This increases the portability
    98123  of the printf() format.
     124
    99125* Do not use the register keyword. It is deprecated since C++14.
    100126
Note: See TracChangeset for help on using the changeset viewer.