Skip to content

Commit 3edad55

Browse files
devel@edk2.groups.iomdkinney
authored andcommitted
Update Chapter 5 Source Files examples to follow the coding standard
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 <[email protected]> Reviewed-by: Michael D Kinney <[email protected]>
1 parent 0d88b47 commit 3edad55

File tree

4 files changed

+18
-18
lines changed

4 files changed

+18
-18
lines changed

5_source_files/52_spacing.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,10 @@ by && or || must have each sub-expression on a separate line. The opening brace,
103103
column of the associated keyword.
104104

105105
```c
106-
while ( ( Code == MEETS_STANDARD)
107-
&& ( Code == FUNCTIONAL))
106+
while ((Code == MEETS_STANDARD)
107+
&& (Code == FUNCTIONAL))
108108
{
109-
ShipIt();
109+
ShipIt ();
110110
}
111111
```
112112

@@ -220,7 +220,7 @@ This is not the case. The bitwise OR operator, '`|`', has lower precedence than
220220
the equality operator, '`==`'. This results in the expression being evaluated as
221221
if one had entered:
222222
```
223-
8 | ( 8 == 8 )
223+
8 | (8 == 8)
224224
```
225225

226226
This evaluates to the value 9.

5_source_files/54_code_file_structure.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,12 @@ and hide each other. Never write code that does this.
151151
7 {
152152
8 UINT32 i;
153153
9
154-
10 for ( i = 0; i < 5; ++i) {
154+
10 for (i = 0; i < 5; ++i) {
155155
11 UCHAR8 MyVar = i; // Block scope
156156
12 INT16 i = 12;
157157
13
158158
14 MyVar += 'A';
159-
15 process ( MyVar, i);
159+
15 process (MyVar, i);
160160
16 }
161161
17 *MyVar = i;
162162
18 }
@@ -165,8 +165,8 @@ and hide each other. Never write code that does this.
165165
21 {
166166
22 UINT32 George = 4;
167167
23
168-
24 MyFunction ( &George);
169-
25 process ( MyVar, 0);
168+
24 MyFunction (&George);
169+
25 process (MyVar, 0);
170170
26 }
171171
27
172172
```

5_source_files/55_preprocessor_directives.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,18 +77,18 @@ An order-of-precedence bug in a macro is very hard to debug. The following are
7777
examples of macro construction:
7878

7979
```
80-
#define BAD_MACRO(a, b) a*b
81-
#define GOOD_MACRO(a, b) ((a)*(b))
80+
#define BAD_MACRO(a, b) a * b
81+
#define GOOD_MACRO(a, b) ((a) * (b))
8282
```
8383

8484
The following examples should explain the difference between `BAD_MACRO ()` and
8585
`GOOD_MACRO ()`:
8686

8787
* `BAD_MACRO (10, 2)` and `GOOD_MACRO (10, 2)` both evaluate to 20.
8888

89-
* `BAD_MACRO (7+3, 2)` returns 13 = 7 + (3*2).
89+
* `BAD_MACRO (7 + 3, 2)` returns 13 = 7 + (3 * 2).
9090

91-
* `GOOD_MACRO (7+3, 2)` returns 20.
91+
* `GOOD_MACRO (7 + 3, 2)` returns 20.
9292

9393
Also, consider the following expression:
9494

@@ -102,7 +102,7 @@ the equality operator, '`==`'. This results in the expression being evaluated as
102102
if one had entered:
103103

104104
```
105-
8 | ( 8 == 8 )
105+
8 | (8 == 8)
106106
```
107107

108108
This evaluates to the value 9 The desired result of `TRUE`, (1), can be achieved
@@ -123,7 +123,7 @@ or a simple substitution macro.
123123
Failure to do this will cause the build to break.
124124

125125
```
126-
#define GOOD_MACRO(a, b) ((a)*(b))
126+
#define GOOD_MACRO(a, b) ((a) * (b))
127127
```
128128

129129
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
146146
and consistency with other coding style rules.
147147

148148
```
149-
GOOD_MACRO (7+3, 2)
149+
GOOD_MACRO (7 + 3, 2)
150150
```
151151

152152
#### 5.5.2.7 Single-line Functions

5_source_files/57_c_programming.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ Module parameters of a PERF_END invocation.
259259

260260
```c
261261
for (Index = 0; Index < NumberOfEntries; Index++) {
262-
if (( LogEntryArray[Index].Handle == (EFI_PHYSICAL_ADDRESS)(UINTN) Handle)
262+
if ((LogEntryArray[Index].Handle == (EFI_PHYSICAL_ADDRESS)(UINTN) Handle)
263263
&& AsciiStrnCmp (LogEntryArray[Index].Token, Token, PEI_PERFORMANCE_STRING_LENGTH) == 0
264264
&& AsciiStrnCmp (LogEntryArray[Index].Module, Module, PEI_PERFORMANCE_STRING_LENGTH) == 0
265265
&& LogEntryArray[Index].EndTimeStamp == 0
@@ -301,7 +301,7 @@ Re-ordering the predicate expression using this information produces:
301301

302302
```c
303303
for (Index = 0; Index < NumberOfEntries; Index++) {
304-
if ( LogEntryArray[Index].EndTimeStamp == 0
304+
if (LogEntryArray[Index].EndTimeStamp == 0
305305
&& LogEntryArray[Index].Handle == (EFI_PHYSICAL_ADDRESS)(UINTN) Handle
306306
&& AsciiStrnCmp (LogEntryArray[Index].Module, Module, PEI_PERFORMANCE_STRING_LENGTH) == 0
307307
&& AsciiStrnCmp (LogEntryArray[Index].Token, Token, PEI_PERFORMANCE_STRING_LENGTH) == 0
@@ -495,7 +495,7 @@ a `goto`.
495495

496496
```c
497497
Status = IAmTheCode ();
498-
if (! EFI_ERROR (Status)) {
498+
if (!EFI_ERROR (Status)) {
499499
IDoTheWork ();
500500
}
501501
return Status;

0 commit comments

Comments
 (0)