Skip to content

Commit 1458476

Browse files
committed
fixup! Add new C coding style guide
1 parent a4e53bd commit 1458476

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

C_CODING_STYLE.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -901,6 +901,7 @@ typedef struct
901901
size_t count_spaces(const char *str);
902902
bool starts_with(const char *str, const char *prefix);
903903
```
904+
904905
- **Conversely**: `parse_iso8601_buf()` needs `_buf` suffix when parsing from a buffer
905906

906907
#### Module Prefixing [AVMCCS-N017]
@@ -1096,14 +1097,17 @@ func(target, inputs, outputs, options, environment)
10961097
#### Parameter Types
10971098
10981099
1. **target**: The primary parameter being operated on (must be initialized)
1100+
10991101
```c
11001102
bool date_time_is_valid(const DateTime *dt);
11011103
void date_time_add_days(DateTime *dt, int days);
11021104
void buffer_append(Buffer *buf, const char *data);
11031105
```
1106+
11041107
Exception: `_init` and `_create` functions initialize the target parameter
11051108

11061109
2. **inputs**: Additional input data with `const` qualification
1110+
11071111
```c
11081112
// Arrays/buffers must always be followed by their length
11091113
void hash_update(Hash *h, const uint8_t data[], size_t data_len);
@@ -1112,15 +1116,18 @@ func(target, inputs, outputs, options, environment)
11121116
```
11131117
11141118
3. **outputs**: Usually uninitialized output parameters (come after inputs)
1119+
11151120
```c
11161121
// Parse functions: input data first, then output location
11171122
parse_int_result_t parse_int(const char *str, int32_t *out);
11181123
base64_decode_result_t base64_decode(const char *encoded,
11191124
uint8_t decoded[], size_t *decoded_len);
11201125
```
1126+
11211127
Note: Additional read-write parameters may precede pure output parameters when it makes semantic sense
11221128

11231129
4. **options**: Function options (prefer enums for clarity)
1130+
11241131
```c
11251132
void user_message_show(Display *display, const char *msg,
11261133
user_message_style_t style);
@@ -1129,6 +1136,7 @@ func(target, inputs, outputs, options, environment)
11291136
```
11301137
11311138
5. **environment**: Context or environment pointers (avoid globals)
1139+
11321140
```c
11331141
void log_message(Logger *logger, const char *msg, log_level_t level,
11341142
Environment *env);
@@ -1899,6 +1907,7 @@ static uint32_t crc32_byte(uint32_t crc, uint8_t byte);
18991907
Choose documentation depth based on API complexity and safety requirements:
19001908

19011909
1. **Minimal**: Self-documenting functions need only brief description
1910+
19021911
```c
19031912
/**
19041913
* @brief Check if buffer is empty
@@ -1907,6 +1916,7 @@ Choose documentation depth based on API complexity and safety requirements:
19071916
```
19081917
19091918
2. **Standard**: Add parameters, return values, and specific error codes [AVMCCS-D014]
1919+
19101920
```c
19111921
/**
19121922
* @brief Parse integer from string
@@ -1922,6 +1932,7 @@ Choose documentation depth based on API complexity and safety requirements:
19221932
```
19231933

19241934
3. **Safety-Critical**: Add preconditions, warnings, and detailed behavior [AVMCCS-D015]
1935+
19251936
```c
19261937
/**
19271938
* @brief Resize dynamic buffer

0 commit comments

Comments
 (0)