EasyManua.ls Logo

Espressif ESP32-S2 - Page 1580

Espressif ESP32-S2
1695 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
Chapter 6. Contributions Guide
(continued from previous page)
}
}
The maximum line length is 120 characters as long as it doesnt seriously affect the readability.
Horizontal Space Always add single space after conditional and loop keywords:
if (condition) { // correct
// ...
}
switch (n) { // correct
case 0:
// ...
}
for(int i = 0; i < CONST; ++i) { // INCORRECT
// ...
}
Add single space around binary operators. No space is necessary for unary operators. It is okay to drop space around
multiply and divide operators:
const int y = y0 + (x - x0) * (y1 - y0) / (x1 - x0); // correct
const int y = y0 + (x - x0)*(y1 - y0)/(x1 - x0); // also okay
int y_cur = -y; // correct
++y_cur;
const int y = y0+(x-x0)*(y1-y0)/(x1-x0); // INCORRECT
No space is necessary around . and -> operators.
Sometimes adding horizontal space within a line can help make code more readable. For example, you can add space
to align function arguments:
esp_rom_gpio_connect_in_signal(PIN_CAM_D6, I2S0I_DATA_IN14_IDX, false);
esp_rom_gpio_connect_in_signal(PIN_CAM_D7, I2S0I_DATA_IN15_IDX, false);
esp_rom_gpio_connect_in_signal(PIN_CAM_HREF, I2S0I_H_ENABLE_IDX, false);
esp_rom_gpio_connect_in_signal(PIN_CAM_PCLK, I2S0I_DATA_IN15_IDX, false);
Note however that if someone goes to add new line with a longer identifier as first argument (e.g. PIN_CAM_VSYNC),
it will not fit. So other lines would have to be realigned, adding meaningless changes to the commit.
Therefore, use horizontal alignment sparingly, especially if you expect new lines to be added to the list later.
Never use TAB characters for horizontal alignment.
Never add trailing whitespace at the end of the line.
Braces
Function definition should have a brace on a separate line:
// This is correct:
void function(int arg)
{
}
(continues on next page)
Espressif Systems 1569
Submit Document Feedback
Release v4.4

Table of Contents