Skip to content

Commit a4d59ee

Browse files
author
XuhuaHuang
committed
Update unions_align.cpp
Refactor union topic source file
1 parent 09c9efc commit a4d59ee

1 file changed

Lines changed: 11 additions & 11 deletions

File tree

Miscellaneous/unions_align.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// clang-format off
12
/*****************************************************************//**
23
* \file unions_align.cpp
34
* \brief contains notes and examples on unions
@@ -9,6 +10,7 @@
910
* \author Xuhua Huang
1011
* \date June 2021
1112
*********************************************************************/
13+
// clang-format on
1214

1315
#include <iostream>
1416

@@ -32,11 +34,8 @@ struct Vector4D {
3234
};
3335
};
3436

35-
void printVector2D(const Vector2D& vector) {
36-
std::cout << __func__ << "\n"
37-
<< "Printing struct Vector2D, x: " << vector.x << ", y: " << vector.y << "\n";
38-
39-
return;
37+
void print_vector2d(const Vector2D& vector) {
38+
std::cout << __func__ << ", x: " << vector.x << ", y: " << vector.y << "\n";
4039
}
4140

4241
int main(void) {
@@ -49,18 +48,19 @@ int main(void) {
4948
*/
5049

5150
Vector4D vector = {1.0f, 2.0f, 3.0f, 4.0f};
52-
printVector2D(vector.v1); // retrieving member in the second anonymous struct
51+
print_vector2d(vector.v1); // retrieving member in the second anonymous struct
5352
// 1.0 and 2.0
54-
printVector2D(vector.v2);
53+
print_vector2d(vector.v2);
5554
// 3.0 and 4.0
5655

57-
/* Change elements in the first anonymous struct
56+
/**
57+
* Change elements in the first anonymous struct
5858
* and verify change in the second anonymous struct
5959
*/
6060
vector.z = 16.0f;
61-
printVector2D(vector.v1); // nothing changes here, prints 1.0 and 2.0
62-
printVector2D(vector.v2); // 16.0 and 4.0
61+
print_vector2d(vector.v1); // nothing changes here, prints 1.0 and 2.0
62+
print_vector2d(vector.v2); // 16.0 and 4.0
6363
// memory address of float z is aligned with Vector2D v2.x [first element in v2]
6464

6565
return 0;
66-
}
66+
}

0 commit comments

Comments
 (0)