Identifiants » Historique » Version 10
Patrice Nadeau, 2024-01-27 15:25
| 1 | 6 | Patrice Nadeau | # Objets |
|---|---|---|---|
| 2 | 3 | Patrice Nadeau | |
| 3 | ## Règles |
||
| 4 | |||
| 5 | 2 | Patrice Nadeau | 1. Comportent au maximum **31** caractères : |
| 6 | 1. Lettres minuscules |
||
| 7 | 4 | Patrice Nadeau | > Les macros sont en lettres majuscules |
| 8 | 2 | Patrice Nadeau | 1. Nombres |
| 9 | 1. Trait de soulignement |
||
| 10 | 1. Si plusieurs mots sont utilisés, ils sont séparées par des traits de soulignement |
||
| 11 | 1. Les objets ne devant plus être utilisés, DOIVENT générer un message lors de la compilation (`-Wall`) si un appel est effectué. |
||
| 12 | 1. Les attributs`deprecated` ou `unavailable` DOIVENT être ajoutés à la déclaration. |
||
| 13 | 7 | Patrice Nadeau | 1. Les commentaires Doxygen suivants doivent être ajoutés : |
| 14 | 1. `@deprecated` : |
||
| 15 | 1. `@since` : |
||
| 16 | 1 | Patrice Nadeau | |
| 17 | 3 | Patrice Nadeau | ## Exemple |
| 18 | 1 | Patrice Nadeau | ``` c |
| 19 | /** |
||
| 20 | * @brief OldFunction |
||
| 21 | * @deprecated Utiliser NewFunction à la place |
||
| 22 | * @since Version x.x.xx |
||
| 23 | */ |
||
| 24 | int OldFunction(void) __attribute__((deprecated)); |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @brief OldFunction |
||
| 28 | * @deprecated Utiliser NewFunction à la place |
||
| 29 | * @since Version x.x.xx |
||
| 30 | */ |
||
| 31 | int OldFunction(void) __attribute__((unavailable)); |
||
| 32 | 4 | Patrice Nadeau | |
| 33 | /** |
||
| 34 | * @brief MACRO1 |
||
| 35 | * @deprecated Utiliser NEWMACRO à la place |
||
| 36 | 1 | Patrice Nadeau | * @since Version x.x.xx |
| 37 | */ |
||
| 38 | #define MACRO1 43 |
||
| 39 | #pragma GCC poison MACRO1 |
||
| 40 | ``` |
||
| 41 | 5 | Patrice Nadeau | |
| 42 | ## Justification |
||
| 43 | * Linux kernel coding style : <https://www.kernel.org/doc/html/v4.10/process/coding-style.html#naming> |
||
| 44 | * GNU Coding Standards <https://www.gnu.org/prep/standards/html_node/Writing-C.html#Writing-C> |
||
| 45 | * Embedded C Coding Standard : <https://barrgroup.com/embedded-systems/books/embedded-c-coding-standard> |
||
| 46 | 1 | Patrice Nadeau | |
| 47 | ### Déclarations locales |
||
| 48 | |||
| 49 | Une déclaration n’ayant qu’une visibilité locale DOIT : |
||
| 50 | * Être de classe `static` |
||
| 51 | |||
| 52 | Exemple: |
||
| 53 | ``` c |
||
| 54 | /** |
||
| 55 | * @brief Fonction locale |
||
| 56 | * @return Une valeur |
||
| 57 | */ |
||
| 58 | static int local_func(void) { |
||
| 59 | ... |
||
| 60 | return 0; |
||
| 61 | } |
||
| 62 | ``` |
||
| 63 | |||
| 64 | ### Constantes |
||
| 65 | |||
| 66 | Utilisé au lieu d’une macro quand le type ou la visibilité de la variable doit être définis. |
||
| 67 | |||
| 68 | Exemple : |
||
| 69 | |||
| 70 | ``` c |
||
| 71 | /** |
||
| 72 | * @name Liste des constantes |
||
| 73 | * @brief |
||
| 74 | */ |
||
| 75 | /** @{ */ |
||
| 76 | /** @brief La chaîne d'initialisation du projet */ |
||
| 77 | static const char INIT_STR[6] = "POWER"; |
||
| 78 | /** @brief Constante globale de la librairie `random` */ |
||
| 79 | extern int RANDOM_MAX = 25; |
||
| 80 | /** @} */ |
||
| 81 | |||
| 82 | /** @brief Constante */ |
||
| 83 | const int ANSWER 42; |
||
| 84 | ``` |
||
| 85 | |||
| 86 | ### Typedef |
||
| 87 | |||
| 88 | Format : |
||
| 89 | * En minuscule, suivie de **_t** |
||
| 90 | |||
| 91 | Exemple : |
||
| 92 | ``` c |
||
| 93 | /** Type de la structure dans la librairie `ds1305` */ |
||
| 94 | typedef struct { |
||
| 95 | /** @brief Dernier deux chiffres : ≥ 00, ≤ 99 */ |
||
| 96 | uint8_t year; |
||
| 97 | /** @brief 01 - 12 */ |
||
| 98 | uint8_t month; |
||
| 99 | /** @brief 01 - 31 */ |
||
| 100 | uint8_t date; |
||
| 101 | /** @brief 1 - 7 */ |
||
| 102 | uint8_t day; |
||
| 103 | /** @brief 00 - 23 */ |
||
| 104 | uint8_t hours; |
||
| 105 | /** @brief 00 - 59 */ |
||
| 106 | uint8_t minutes; |
||
| 107 | /** @brief 00 - 59 */ |
||
| 108 | uint8_t seconds; |
||
| 109 | } ds1305_time_t; |
||
| 110 | ``` |
||
| 111 | |||
| 112 | ### Variables |
||
| 113 | |||
| 114 | Exemple : |
||
| 115 | ``` c |
||
| 116 | /** @brief Variable locale */ |
||
| 117 | static int ctr; |
||
| 118 | /** @brief Variable globale */ |
||
| 119 | int RANDOM_CTR; |
||
| 120 | ``` |