public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [edk2-CCodingStandardsSpecification PATCH 1/1] Update Chapter 5 Source Files examples to follow the coding standard
@ 2020-12-08 12:26 Rebecca Cran
  2020-12-08 21:46 ` [edk2-devel] " Michael D Kinney
  0 siblings, 1 reply; 3+ messages in thread
From: Rebecca Cran @ 2020-12-08 12:26 UTC (permalink / raw)
  To: devel
  Cc: Rebecca Cran, Michael D Kinney, Leif Lindholm, Laszlo Ersek,
	Andrew Fish

There shouldn't be a space after an opening parenthesis, or around
unary operators.

There should be a space before a opening parenthesis and around binary
operators.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Rebecca Cran <rebecca@nuviainc.com>
---
 5_source_files/52_spacing.md                 |  8 ++++----
 5_source_files/54_code_file_structure.md     |  8 ++++----
 5_source_files/55_preprocessor_directives.md | 14 +++++++-------
 5_source_files/57_c_programming.md           |  6 +++---
 4 files changed, 18 insertions(+), 18 deletions(-)

diff --git a/5_source_files/52_spacing.md b/5_source_files/52_spacing.md
index fca0044a148b..9a97466f1d61 100644
--- a/5_source_files/52_spacing.md
+++ b/5_source_files/52_spacing.md
@@ -103,10 +103,10 @@ by && or || must have each sub-expression on a separate line. The opening brace,
 column of the associated keyword.
 
 ```c
-while ( ( Code == MEETS_STANDARD)
-  && ( Code == FUNCTIONAL))
+while ((Code == MEETS_STANDARD)
+  && (Code == FUNCTIONAL))
 {
-  ShipIt();
+  ShipIt ();
 }
 ```
 
@@ -220,7 +220,7 @@ This is not the case. The bitwise OR operator, '`|`', has lower precedence than
 the equality operator, '`==`'. This results in the expression being evaluated as
 if one had entered:
 ```
-8 | ( 8 == 8 )
+8 | (8 == 8)
 ```
 
 This evaluates to the value 9.
diff --git a/5_source_files/54_code_file_structure.md b/5_source_files/54_code_file_structure.md
index caaeab94b68e..0c4d6a26820c 100644
--- a/5_source_files/54_code_file_structure.md
+++ b/5_source_files/54_code_file_structure.md
@@ -151,12 +151,12 @@ and hide each other. Never write code that does this.
  7 {
  8   UINT32 i;
  9
-10   for ( i = 0; i < 5; ++i) {
+10   for (i = 0; i < 5; ++i) {
 11     UCHAR8 MyVar = i; // Block scope
 12     INT16 i = 12;
 13
 14     MyVar += 'A';
-15     process ( MyVar, i);
+15     process (MyVar, i);
 16   }
 17   *MyVar = i;
 18 }
@@ -165,8 +165,8 @@ and hide each other. Never write code that does this.
 21 {
 22   UINT32 George = 4;
 23
-24   MyFunction ( &George);
-25   process ( MyVar, 0);
+24   MyFunction (&George);
+25   process (MyVar, 0);
 26 }
 27
 ```
diff --git a/5_source_files/55_preprocessor_directives.md b/5_source_files/55_preprocessor_directives.md
index 98839f6677a8..3075285b7e31 100644
--- a/5_source_files/55_preprocessor_directives.md
+++ b/5_source_files/55_preprocessor_directives.md
@@ -77,8 +77,8 @@ An order-of-precedence bug in a macro is very hard to debug. The following are
 examples of macro construction:
 
 ```
-#define BAD_MACRO(a, b) a*b
-#define GOOD_MACRO(a, b) ((a)*(b))
+#define BAD_MACRO(a, b) a * b
+#define GOOD_MACRO(a, b) ((a) * (b))
 ```
 
 The following examples should explain the difference between `BAD_MACRO ()` and
@@ -86,9 +86,9 @@ The following examples should explain the difference between `BAD_MACRO ()` and
 
 * `BAD_MACRO (10, 2)` and `GOOD_MACRO (10, 2)` both evaluate to 20.
 
-* `BAD_MACRO (7+3, 2)` returns 13 = 7 + (3*2).
+* `BAD_MACRO (7 + 3, 2)` returns 13 = 7 + (3 * 2).
 
-* `GOOD_MACRO (7+3, 2)` returns 20.
+* `GOOD_MACRO (7 + 3, 2)` returns 20.
 
 Also, consider the following expression:
 
@@ -102,7 +102,7 @@ the equality operator, '`==`'. This results in the expression being evaluated as
 if one had entered:
 
 ```
-8 | ( 8 == 8 )
+8 | (8 == 8)
 ```
 
 This evaluates to the value 9 The desired result of `TRUE`, (1), can be achieved
@@ -123,7 +123,7 @@ or a simple substitution macro.
 Failure to do this will cause the build to break.
 
 ```
-#define GOOD_MACRO(a, b) ((a)*(b))
+#define GOOD_MACRO(a, b) ((a) * (b))
 ```
 
 This is because the compiler has no way to differentiate between
@@ -146,7 +146,7 @@ Failure to separate macro names from parameters negatively impacts readability
 and consistency with other coding style rules.
 
 ```
-GOOD_MACRO (7+3, 2)
+GOOD_MACRO (7 + 3, 2)
 ```
 
 #### 5.5.2.7 Single-line Functions
diff --git a/5_source_files/57_c_programming.md b/5_source_files/57_c_programming.md
index 8b9db584eea7..a167f925536f 100644
--- a/5_source_files/57_c_programming.md
+++ b/5_source_files/57_c_programming.md
@@ -259,7 +259,7 @@ Module parameters of a PERF_END invocation.
 
 ```c
 for (Index = 0; Index < NumberOfEntries; Index++) {
-  if (( LogEntryArray[Index].Handle == (EFI_PHYSICAL_ADDRESS)(UINTN) Handle)
+  if ((LogEntryArray[Index].Handle == (EFI_PHYSICAL_ADDRESS)(UINTN) Handle)
        && AsciiStrnCmp (LogEntryArray[Index].Token, Token, PEI_PERFORMANCE_STRING_LENGTH) == 0
        && AsciiStrnCmp (LogEntryArray[Index].Module, Module, PEI_PERFORMANCE_STRING_LENGTH) == 0
        && LogEntryArray[Index].EndTimeStamp == 0
@@ -301,7 +301,7 @@ Re-ordering the predicate expression using this information produces:
 
 ```c
 for (Index = 0; Index < NumberOfEntries; Index++) {
-  if ( LogEntryArray[Index].EndTimeStamp == 0
+  if (LogEntryArray[Index].EndTimeStamp == 0
        && LogEntryArray[Index].Handle == (EFI_PHYSICAL_ADDRESS)(UINTN) Handle
        && AsciiStrnCmp (LogEntryArray[Index].Module, Module, PEI_PERFORMANCE_STRING_LENGTH) == 0
        && AsciiStrnCmp (LogEntryArray[Index].Token, Token, PEI_PERFORMANCE_STRING_LENGTH) == 0
@@ -495,7 +495,7 @@ a `goto`.
 
 ```c
 Status = IAmTheCode ();
-if (! EFI_ERROR (Status)) {
+if (!EFI_ERROR (Status)) {
   IDoTheWork ();
 }
 return Status;
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-12-11 19:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-12-08 12:26 [edk2-CCodingStandardsSpecification PATCH 1/1] Update Chapter 5 Source Files examples to follow the coding standard Rebecca Cran
2020-12-08 21:46 ` [edk2-devel] " Michael D Kinney
2020-12-11 19:40   ` Michael D Kinney

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox