Concept
How should structure names and member variables be declared in C?
ComputerScienceOne / Nested Structures
"typedef struct Student { 2 ... 3 } Student; Which places the Student identifier in both the global space and in the “structure” space. Which style of declaration you use depends on several factors, but for simplicity we’ll stick with the first style. In addition, you may see some older naming conventions use lowercase underscore naming for structure names. In particular, POSIX systems use names that end with _t (indicating a structure type). You should avoid such naming conventions to avoid conflicts. Finally, though C does not provide a mechanism for the protection of data, many libraries and code bases will begin certain member variables with underscore(s) to indicate that they are “internal” variables used by the library and should not be accessed or modified. For example, _someVariable or __anotherVariable would indicate “private” variables that should not be tampered with. The C language itself would still allow you access and modify the variables, but doing so may violate assumptions and expectations of the library code, leading to undefined behavior."
Related Ideas
- How are structures defined and named in C?ComputerScienceOne · Alternative Declarations
- What is the alternative way to declare a structure in C?ComputerScienceOne · Alternative Declarations
- How do you declare variables in C?ComputerScienceOne · Declaration & Assignment
- How are structure instances declared and initialized?ComputerScienceOne · Declaration & Initialization
- How can one structure be composed of another structure?ComputerScienceOne · Declaration & Initialization
- How do you access members of a statically declared structure?ComputerScienceOne · Selection Operators
- What are the basic syntax rules of C?ComputerScienceOne · Basic Syntax Rules
- How do you access members through a pointer to a structure?ComputerScienceOne · Selection Operators