You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Clarify the language around zero initialization. (#157)
* Clarify the language around zero initialization.
Signed-off-by: Chris Lalancette <[email protected]>
* Fix up feedback from review.
Signed-off-by: Chris Lalancette <[email protected]>
* More PR feedback.
Signed-off-by: Chris Lalancette <[email protected]>
Copy file name to clipboardExpand all lines: articles/112_generated_interfaces_cpp.md
+7-5Lines changed: 7 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -103,17 +103,19 @@ All other constants are declared as `static const` members in the struct and the
103
103
104
104
### Constructors
105
105
106
-
The *default constructor* initializes all members with their default value; if a field doesn't have a default value, then the field is [value-initialized](http://en.cppreference.com/w/cpp/language/value_initialization).
106
+
In the following discussion, "member" refers to the class member in the C++ class while "field" refers to the field definition in the IDL file.
107
+
108
+
The *default constructor* initializes all members with their default value; if a field doesn't have a default value, then the member is [value-initialized](http://en.cppreference.com/w/cpp/language/value_initialization).
107
109
In some cases this may not be desirable, since these fields will often be immediately overwritten with user-provided values.
108
110
Therefore, the constructor takes an optional directive of type `rosidl_generator_cpp::MessageInitialization` to control how initialization is done:
109
111
110
-
-`MessageInitialization::ALL` - Initialize all members with their default value; if a field doesn't have a default value, then the field is [value-initialized](http://en.cppreference.com/w/cpp/language/value_initialization)
112
+
-`MessageInitialization::ALL` - Initialize each member with the field's default value; if a field doesn't have a default value, then the member is [value-initialized](http://en.cppreference.com/w/cpp/language/value_initialization)
111
113
- The safest option, and also the default (used if not passing any argument to the constructor).
112
-
-`MessageInitialization::SKIP` - Don't initialize any members; it is the user's responsibility to ensure that all fields get initialized with some value, otherwise undefined behavior may result
114
+
-`MessageInitialization::SKIP` - Don't initialize any members; it is the user's responsibility to ensure that all members get initialized with some value, otherwise undefined behavior may result
113
115
- Used for maximum performance if the user is setting all of the members themselves.
114
-
-`MessageInitialization::ZERO` - Zero initialize all members; this differs from `MessageInitialization::ALL` in that all members will be [value-initialized](http://en.cppreference.com/w/cpp/language/value_initialization), and default values from the message definition will be ignored
116
+
-`MessageInitialization::ZERO` - Zero initialize all members; all members will be [value-initialized](http://en.cppreference.com/w/cpp/language/value_initialization) ([dynamic size](interface_definition.html#arrays-with-dynamic-size) or [upper boundary](interface_definition.html#upper-boundaries) arrays will have zero elements), and default values from the message definition will be ignored
115
117
- Used when the user doesn't want the overhead of initializing potentially complex or large default values, but still wants to ensure that all variables are properly initialized.
116
-
-`MessageInitialization::DEFAULTS_ONLY` - Default initialize only fields that have default values assigned to individual members; all other fields will be left uninitialized
118
+
-`MessageInitialization::DEFAULTS_ONLY` - Initialize only members that have field default values; all other members will be left uninitialized
117
119
- Minimal initialization which ensures that existing code has correctly initialized members when a new field with a default value is added to the IDL later.
118
120
119
121
Optionally the constructor can be invoked with an allocator.
0 commit comments