Skip to content

Commit bda6c02

Browse files
committed
edk II C Coding Standard: Insert Directory Names section
Insert 4.2 Directory names as the placeholder and update markdown file names and content of follow up sections. PR: https://github.com/tianocore-docs/edk2-CCodingStandardsSpecification/pull/2/files Signed-off-by: Abner Chang <[email protected]> Cc: Ray Ni <[email protected]> Cc: Michael D Kinney <[email protected]> Cc: Sunil V L <[email protected]> Cc: Abdul Lateef Attar <[email protected]> Cc: Leif Lindholm <[email protected]> Reviewed-by: Ray Ni <[email protected]> Reviewed-by: Abdul Lateef Attar <[email protected]>
1 parent d2b81c4 commit bda6c02

File tree

7 files changed

+79
-46
lines changed

7 files changed

+79
-46
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<!--- @file
2+
4.2 Directory Names
3+
4+
Copyright (C) 2022 Advanced Micro Devices, Inc. All rights reserved.<BR>
5+
6+
Redistribution and use in source (original document form) and 'compiled'
7+
forms (converted to PDF, epub, HTML and other formats) with or without
8+
modification, are permitted provided that the following conditions are met:
9+
10+
1) Redistributions of source code (original document form) must retain the
11+
above copyright notice, this list of conditions and the following
12+
disclaimer as the first lines of this file unmodified.
13+
14+
2) Redistributions in compiled form (transformed to other DTDs, converted to
15+
PDF, epub, HTML and other formats) must reproduce the above copyright
16+
notice, this list of conditions and the following disclaimer in the
17+
documentation and/or other materials provided with the distribution.
18+
19+
THIS DOCUMENTATION IS PROVIDED BY TIANOCORE PROJECT "AS IS" AND ANY EXPRESS OR
20+
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21+
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
22+
EVENT SHALL TIANOCORE PROJECT BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25+
OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26+
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27+
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS DOCUMENTATION, EVEN IF
28+
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+
30+
-->
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--- @file
2-
4.2 File Names
2+
4.3 File Names
33
44
Copyright (c) 2006-2017, Intel Corporation. All rights reserved.<BR>
55
@@ -29,25 +29,25 @@
2929
3030
-->
3131

32-
## 4.2 File Names
32+
## 4.3 File Names
3333

34-
### 4.2.1 There is no limit to file name lengths.
34+
### 4.3.1 There is no limit to file name lengths.
3535

3636
Do not assume that file names must be 8.3 compatible. Be reasonable though. Let
3737
the file names be as long as necessary, but no longer. Some operating systems
3838
limit file names to 32 characters.
3939

40-
### 4.2.2 Spaces in file and directory names are NOT permitted.
40+
### 4.3.2 Spaces in file and directory names are NOT permitted.
4141

4242
Allowing spaces would cause problems with certain versions of existing industry
4343
tools and does not provide additional clarity.
4444

45-
### 4.2.3 Never start file names with numbers.
45+
### 4.3.3 Never start file names with numbers.
4646

4747
Most source control systems will not be able to handle file names that start
4848
with numbers.
4949

50-
### 4.2.4 Non-standard characters shall not occur in file names.
50+
### 4.3.4 Non-standard characters shall not occur in file names.
5151

5252
All file names within an EDK II source tree must comply with the following
5353
regular expression:
Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--- @file
2-
4.3 Identifiers
2+
4.4 Identifiers
33
44
Copyright (c) 2006-2017, Intel Corporation. All rights reserved.<BR>
55
@@ -29,9 +29,9 @@
2929
3030
-->
3131

32-
## 4.3 Identifiers
32+
## 4.4 Identifiers
3333

34-
### 4.3.1 Identifiers shall not rely on the significance of more than 31 characters.
34+
### 4.4.1 Identifiers shall not rely on the significance of more than 31 characters.
3535

3636
Identifiers (variable names, labels, structure tags, derived macro names, etc.)
3737
may be an arbitrary length. The ISO standard only guarantees that language
@@ -42,17 +42,17 @@ has been confirmed that 31 character / case significance is supported by EDK II
4242
supported tool chains, there is no requirement to ensure uniqueness of
4343
externals within the first 6 characters.
4444

45-
### 4.3.2 Always make identifier names that are visually distinguishable.
45+
### 4.4.2 Always make identifier names that are visually distinguishable.
4646

4747
While not as big an issue as it has been in the past, when choosing labels
4848
ensure that the label is unlikely to be confused with other labels used in the
4949
file. Ensure that long label names vary by more than one or two characters.
5050
Ensure that labels don't vary between zero and oh (0 and O), one and ell (1 and
5151
l). Some also consider 2 and Z, and 5 and S to be similar.
5252

53-
### 4.3.3 Hungarian Prefixes
53+
### 4.4.3 Hungarian Prefixes
5454

55-
#### 4.3.3.1 Use of Hungarian notation is not allowed
55+
#### 4.4.3.1 Use of Hungarian notation is not allowed
5656

5757
This set of detailed guidelines for naming variables and routines is a
5858
convention widely used with the C programming language, especially in
@@ -68,7 +68,7 @@ Global data and module data shall be prefixed with 'g' or 'm', respectively.
6868
Pointer variables may optionally be prefixed with 'p'. These are the only
6969
exceptions to the prohibition against Hungarian notation.
7070

71-
#### 4.3.3.2 Any variable with file scope, or better, shall be prefixed by an 'm' or 'g'
71+
#### 4.4.3.2 Any variable with file scope, or better, shall be prefixed by an 'm' or 'g'
7272

7373
There are no exceptions to this rule. The '`m`' prefix identifies a variable
7474
with module scope, while a '`g`' prefix identifies a global variable.
@@ -78,13 +78,13 @@ gThisIsAGlobalVariableName
7878
mThisIsAModuleVariableName
7979
```
8080

81-
#### 4.3.3.3 Pointer variables may optionally be prefixed with a 'p'
81+
#### 4.4.3.3 Pointer variables may optionally be prefixed with a 'p'
8282

8383
Time has shown that pass-by-value vs. pass-by-reference errors are
8484
significantly reduced with only the introduction of a '`p`' prefix for pointer
8585
variables.
8686

87-
#### 4.3.3.4 Reasons use of Hungarian prefixes not allowed
87+
#### 4.4.3.4 Reasons use of Hungarian prefixes not allowed
8888

8989
The abstraction of abstract data types is ignored. Instead, base types based on
9090
programminglanguage integers or long integers are abstracted. Thus, the names
@@ -100,21 +100,21 @@ Studies have shown that Hungarian notation tends to encourage lazy variable
100100
names. It's common to focus on the Hungarian prefix without putting effort into
101101
a descriptive name.
102102

103-
### 4.3.4 Function and Data Names
103+
### 4.4.4 Function and Data Names
104104

105-
#### 4.3.4.1 Identifiers shall contain mixed upper- and lower-case text.
105+
#### 4.4.4.1 Identifiers shall contain mixed upper- and lower-case text.
106106

107107
Use of all upper- or all lower-case is very difficult to read because compound
108108
words cannot be clearly separated.
109109

110-
#### 4.3.4.2 The names of newly created global entities (such as structures, macros, and defines) shall not use an `EFI_` prefix.
110+
#### 4.4.4.2 The names of newly created global entities (such as structures, macros, and defines) shall not use an `EFI_` prefix.
111111

112112
From now on, the use of `DXE_` and `PEI_` prefixes shall be reserved for DXE and
113113
PEI drivers, respectively. If a structure happens to apply equally to PEI and
114114
DXE, it should use the prefix `DXE_`. If a structure is local to a particular
115115
module only, no special prefix is required.
116116

117-
#### 4.3.4.3 Acronyms are not capitalized in Function and Data Names.
117+
#### 4.4.4.3 Acronyms are not capitalized in Function and Data Names.
118118

119119
When all letters in an acronym are capitalized, it makes the prior and
120120
subsequent words visually difficult to distinguish.
@@ -123,14 +123,14 @@ subsequent words visually difficult to distinguish.
123123
ThisIsAnExampleOfWhatToDoForPci
124124
```
125125

126-
#### 4.3.4.4 Never use C keywords or the names of symbols declared in the standard header files as internal symbols.
126+
#### 4.4.4.4 Never use C keywords or the names of symbols declared in the standard header files as internal symbols.
127127

128128
When you need to use the name of an existing library function for a
129129
user-defined function, each use of the user-defined function must be paired
130130
with a corresponding comment. The ISO standard does not, however, guarantee
131131
that the user-defined function will take priority over the library function.
132132

133-
##### 4.3.4.4.1 List of the C-reserved keywords.
133+
##### 4.4.4.4.1 List of the C-reserved keywords.
134134

135135
In principle, the ISO standard, reserves all names beginning with underscore +
136136
capital letter, or with underscore + underscore. External symbols names shall
@@ -162,23 +162,23 @@ not begin with an underscore.
162162
In addition to those listed, the identifiers asm and fortran are common
163163
language extensions and should also be treated as reserved.
164164

165-
### 4.3.5 Type and Macro Names
165+
### 4.4.5 Type and Macro Names
166166

167-
#### 4.3.5.1 Use all capital letters for both #define and typedef declarations.
167+
#### 4.4.5.1 Use all capital letters for both #define and typedef declarations.
168168

169169
This clearly differentiates static declarations from dynamic data types.
170170

171-
#### 4.3.5.2 Each word of a concept shall be separated by an underscore character.
171+
#### 4.4.5.2 Each word of a concept shall be separated by an underscore character.
172172

173173
The underscore effectively separates the words, making names more readable.
174174

175-
#### 4.3.5.3 The use of the "_t" suffix, designating a type, is not allowed.
175+
#### 4.4.5.3 The use of the "_t" suffix, designating a type, is not allowed.
176176

177177
```
178178
typedef UINT32 THIS_IS_AN_EXAMPLE_OF_WHAT_TO_DO_FOR_PCI;
179179
```
180180

181-
#### 4.3.5.4 The names of guard macros shall end with an underscore character.
181+
#### 4.4.5.4 The names of guard macros shall end with an underscore character.
182182

183183
The guard macro, used in the `#ifndef` at the start of an include file, uses a
184184
postfix underscore character '`_`', in its name in order to prevent collision
@@ -200,7 +200,7 @@ be required if the header files are mutually exclusive.
200200
#endif /* FILE_NAME_H_ */
201201
```
202202

203-
#### 4.3.5.5 The #else and #endif clauses of conditional compilation blocks shall be commented to identify their context.
203+
#### 4.4.5.5 The #else and #endif clauses of conditional compilation blocks shall be commented to identify their context.
204204

205205
If a conditional compilation construct spans more than seven lines, a comment
206206
shall be added to the construct's `#else` and `#endif` clauses identifying the

4_naming_conventions/44_global_&_module_variables.md renamed to 4_naming_conventions/45_global_&_module_variables.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--- @file
2-
4.4 Global & Module Variables
2+
4.5 Global & Module Variables
33
44
Copyright (c) 2006-2017, Intel Corporation. All rights reserved.<BR>
55
@@ -29,7 +29,7 @@
2929
3030
-->
3131

32-
## 4.4 Global & Module Variables
32+
## 4.5 Global & Module Variables
3333

3434
There is often confusion about what constitutes module variables versus global
3535
variables. Technically, both global and module variables are defined at file
@@ -45,9 +45,9 @@ small number of routines. On the other hand, a global variable is accessed
4545
throughout the firmware and as the firmware evolves more code will tend to
4646
access the data resulting in a large number of uses to track down.
4747

48-
### 4.4.1 Recommendations for Global and Module Variables
48+
### 4.5.1 Recommendations for Global and Module Variables
4949

50-
#### 4.4.1.1 The use of global and module data is strongly discouraged.
50+
#### 4.5.1.1 The use of global and module data is strongly discouraged.
5151

5252
Global variables are appropriate for GUID, protocol, PPI definitions and other
5353
immutable objects. Attempting to create global variables can cause many
@@ -59,7 +59,7 @@ programming issues. A module is defined to be a set of data and routines that
5959
act on that data. Thus, in EFI a protocol could be thought of as a module. A
6060
complicated protocol may be built out of several smaller modules.
6161

62-
#### 4.4.1.2 Use locking to protect access to global and module variables.
62+
#### 4.5.1.2 Use locking to protect access to global and module variables.
6363

6464
This protection is strongly encouraged and especially useful for data that is
6565
accessed at various task priority levels.

4_naming_conventions/45_name_space_rules.md renamed to 4_naming_conventions/46_name_space_rules.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--- @file
2-
4.5 Name Space Rules
2+
4.6 Name Space Rules
33
44
Copyright (c) 2006-2017, Intel Corporation. All rights reserved.<BR>
55
@@ -29,7 +29,7 @@
2929
3030
-->
3131

32-
## 4.5 Name Space Rules
32+
## 4.6 Name Space Rules
3333

3434
ISO C defines several name spaces (see ISO/IEC 9899:1994 6.1.2.3). The same
3535
name could be used in a separate name space for a completely different item.
@@ -46,7 +46,7 @@ Name spaces are defined as:
4646
apply to scope. Scope is described in "Scoping Rules".
4747
**********
4848

49-
### 4.5.1 Names shall be used consistently within the same type.
49+
### 4.6.1 Names shall be used consistently within the same type.
5050

5151
For example, structure tags may only be reused as structure types, and union
5252
tags may be reused only for union types.
@@ -62,7 +62,7 @@ typedef struct MyStruct {
6262
Because of the similarity of `MyStruct` to `MY_STRUCT`, they may only be used
6363
to refer to the same structure type.
6464

65-
### 4.5.2 No identifier in one name space may be reused as an identifier in another name space
65+
### 4.6.2 No identifier in one name space may be reused as an identifier in another name space
6666

6767
Exceptions are structure member and union member names.
6868

@@ -85,10 +85,10 @@ typedef struct {
8585
} BAD_STRUCT;
8686
```
8787

88-
### 4.5.3 A typedef name shall be a unique identifier.
88+
### 4.6.3 A typedef name shall be a unique identifier.
8989

9090
The name that appears at the end of a typedef (`STRUCT_ONE` and `STRUCT_TWO` in
91-
the example in Section 4.5.2) is known as a _typedef name_. Because of ambiguity
91+
the example in Section 4.6.2) is known as a _typedef name_. Because of ambiguity
9292
in the C specifications, and to avoid confusion, and once a typedef name is used
9393
in a structure declaration, it may not be declared elsewhere
9494

@@ -97,10 +97,10 @@ in a structure declaration, it may not be declared elsewhere
9797
number of files is not a violation of this rule.
9898
**********
9999

100-
### 4.5.4 A tag name shall be unique.
100+
### 4.6.4 A tag name shall be unique.
101101

102102
The name after the `struct` in structure definitions (`StructOne` and
103-
`StructTwo` in the example in 4.5.2) is known as a _structure tag_ or simply a
103+
`StructTwo` in the example in 4.6.2) is known as a _structure tag_ or simply a
104104
_tag_. To avoid confusion, once a tag is used for declaring a structure it
105105
shall not be declared elsewhere.
106106

@@ -109,7 +109,7 @@ shall not be declared elsewhere.
109109
violation of this rule.
110110
**********
111111

112-
### 4.5.5 Prefix module-scope identifiers for cleaner namespaces.
112+
### 4.6.5 Prefix module-scope identifiers for cleaner namespaces.
113113

114114
The use of prefixes is not an absolute requirement, but has been shown as a
115115
successful method of avoiding namespace pollution and makes it easier to meet

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,4 @@ Copyright (c) 2006-2017, Intel Corporation. All rights reserved.
114114
| | [#425](https://bugzilla.tianocore.org/show_bug.cgi?id=425) [CCS] clarify line breaking and indentation requirements for multi-line function calls | |
115115
| | [#1656](https://bugzilla.tianocore.org/show_bug.cgi?id=1656) Update all Wiki pages for the BSD+Patent license change with SPDX identifiers | |
116116
| | [#607](https://bugzilla.tianocore.org/show_bug.cgi?id=607) Document code comment requirements for spurious variable assignments | |
117+
| 2.3 | Add 4.2 Directory names section and update File names section for the guidelines of module directory and file naming|September 2022||

SUMMARY.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<!--- @file
22
Summary
33
4-
Copyright (c) 2006-2017, Intel Corporation. All rights reserved.<BR>
4+
Copyright (c) 2006-2022, Intel Corporation. All rights reserved.<BR>
5+
Copyright (C) 2022 Advanced Micro Devices, Inc. All rights reserved.<BR>
56
67
Redistribution and use in source (original document form) and 'compiled'
78
forms (converted to PDF, epub, HTML and other formats) with or without
@@ -49,10 +50,11 @@
4950
* [3.4 Documentation](3_quick_reference.md#34-documentation)
5051
* [4 Naming Conventions](4_naming_conventions/README.md#4-naming-conventions)
5152
* [4.1 General Naming Rules](4_naming_conventions/README.md#41-general-naming-rules)
52-
* [4.2 File Names](4_naming_conventions/42_file_names.md#42-file-names)
53-
* [4.3 Identifiers](4_naming_conventions/43_identifiers.md#43-identifiers)
54-
* [4.4 Global & Module Variables](4_naming_conventions/44_global_&_module_variables.md#44-global--module-variables)
55-
* [4.5 Name Space Rules](4_naming_conventions/45_name_space_rules.md#45-name-space-rules)
53+
* [4.2 Directory Names](4_naming_conventions/42_file_names.md#42-directory-names)
54+
* [4.3 File Names](4_naming_conventions/43_file_names.md#43-file-names)
55+
* [4.4 Identifiers](4_naming_conventions/44_identifiers.md#44-identifiers)
56+
* [4.5 Global & Module Variables](4_naming_conventions/45_global_&_module_variables.md#45-global--module-variables)
57+
* [4.6 Name Space Rules](4_naming_conventions/46_name_space_rules.md#46-name-space-rules)
5658
* [5 Source Files](5_source_files/README.md#5-source-files)
5759
* [5.1 General Rules](5_source_files/README.md#51-general-rules)
5860
* [5.2 Spacing](5_source_files/52_spacing.md#52-spacing)

0 commit comments

Comments
 (0)