From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-il1-f197.google.com (mail-il1-f197.google.com [209.85.166.197]) by mx.groups.io with SMTP id smtpd.web11.9840.1607440573656376264 for ; Tue, 08 Dec 2020 07:16:13 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: nuviainc.com, ip: 209.85.166.197, mailfrom: rebecca@nuviainc.com) Received: by mail-il1-f197.google.com with SMTP id j20so13339104ilk.0 for ; Tue, 08 Dec 2020 07:16:13 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=cLnvOoDMpfkE4ZYQi4a3+j3xwvkaFYlv75rl5Ghz7Wg=; b=LegFDpZucJOx/zVlHRV1n9M87HphYXjLnU/q6cWhFtkhRu0O2UbKH/b7rourQDVo+O u7nqzyxQV+xEutMnHTORaYUphVIt7wC/RyGlbAa+/vNNCrpSIN5oHonJ3uvHijGW/dYL H/lLsQZdi02Zp97XTb2YsRp8GyDsGrAy/d8zEMVU9+bTIKqjO62gkhuGx4+RzR9UOdU1 a6A/tX47hpnLH/7UuaCY1M6esRLJtu/4VREzWDAYiFIe62kjs0CFGV7DzmZN1fk78yfi qCFU2IaOzmQLQuhDf7eP25ik43vTDjRFX1UuJzQCFKwKKxVdMJ+v/mlM8RFiaiAZI7vo 5P+Q== X-Gm-Message-State: AOAM5339NFkoU1eRqwDNQuYy6E/NhDanvl7HCPUOzxmaGEmUkXtW6WLL A/K0Sn6NH96POFgjsAEk8zeUGk2QLdIN2Rs6ShcIeWGTIM9EtDwBi62nOZkZQ09WUjzsHdvD2sD Wx4ccnpvcIc13KP5Qz1KX6TxQKjPkBUq4OMwNqULkzb687LaTqbmYl7CuRx19cJYFp/MYrnGVLh z4BVMWUoB2V6/p X-Google-Smtp-Source: ABdhPJzMM6q6Bhx9vHoeKXKHQyiZKSP48DfbdAksfsBV3KN46IHYUETMmqds78GDl2O3QYCDGzwodcdyJ6r8hMIw/F53g4VaFJZDnQ== X-Received: by 2002:a02:9f8b:: with SMTP id a11mr27430266jam.108.1607440573029; Tue, 08 Dec 2020 07:16:13 -0800 (PST) Return-Path: Received: from cube.nuviainc.com (c-174-52-16-57.hsd1.ut.comcast.net. [174.52.16.57]) by smtp.gmail.com with ESMTPSA id b4sm2927118pju.33.2020.12.08.04.26.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Dec 2020 04:26:47 -0800 (PST) From: "Rebecca Cran" To: devel@edk2.groups.io Cc: Rebecca Cran , Michael D Kinney , Leif Lindholm , Laszlo Ersek , Andrew Fish Subject: [edk2-CCodingStandardsSpecification PATCH 1/1] Update Chapter 5 Source Files examples to follow the coding standard Date: Tue, 8 Dec 2020 05:26:38 -0700 Message-Id: <20201208122638.4916-1-rebecca@nuviainc.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- 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