Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coding Style: Braces around single-line statements in if/for blocks? #350

Open
thnkslprpt opened this issue Dec 7, 2022 · 0 comments
Open
Labels

Comments

@thnkslprpt
Copy link
Contributor

thnkslprpt commented Dec 7, 2022

Describe the bug
Most single-line statements (>97%) in if/for blocks are surrounded by braces, but not all.

Expected behavior
If not contrary to the coding standard, no change is required, although consistency is always nice...

Additional context
Most safety-focused coding standards require braces in call blocks, even for single-line statements (and often even for empty statements). I'm not sure where the cFS (GSFC) standard stands on this.

This is due to the perceived improvement in readability and maintainability (i.e. with braces, there is a lower risk of messing up the scope of a statement when something is either added or removed in the future).

Code snips

CF/fsw/src/cf_cfdp_s.c

Lines 789 to 790 in b9a8898

if (ret == 1)
*cont = 1; /* cause dispatcher to re-enter this wakeup */

CF/fsw/src/cf_cmd.c

Lines 596 to 597 in b9a8898

for (i = 0; i < CF_MAX_POLLING_DIR_PER_CHAN; ++i)
CF_AppData.config_table->chan[chan_num].polldir[i].enabled = context->barg;

A few further examples from around cFS to illustrate:
https://github.com/nasa/MD/blob/908165343533c8288631cc5a2a1e9b87dc3fb818/fsw/src/md_utils.c#L49-L50
https://github.com/nasa/to_lab/blob/9e2ad8cccafaad6d09902213971344d9e277e9f9/fsw/src/to_lab_app.c#L216-L219
https://github.com/nasa/cFS-GroundSystem/blob/73935aca4b417c717ef6b6be03bbf5e1ad5b48f5/Subsystems/cmdUtil/cmdUtil.c#L398-L399

Reporter Info
Avi Weiss @thnkslprpt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants