Hi, folks.
I'm following along with the series, currently at day 042. Seeing as I have encountered anonymous unions/structs twice now, thought I'd ask.
I'm working on Mac OS X. I took this platform implementation as the base:
https://github.com/vbo/handmadehero_osx_platform_layer. However, since I have zero knowledge of Objective-C and OS X API, I've rewritten the platform using SFML 2.4.
I am compiling using clang and the following piece of code gives errors:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32 | typedef struct game_controller_input
{
bool32 IsConnected;
bool32 IsAnalog;
real32 StickAverageX;
real32 StickAverageY;
union
{
game_button_state Buttons[12];
struct
{
game_button_state MoveUp;
game_button_state MoveDown;
game_button_state MoveLeft;
game_button_state MoveRight;
game_button_state ActionUp;
game_button_state ActionDown;
game_button_state ActionLeft;
game_button_state ActionRight;
game_button_state LeftShoulder;
game_button_state RightShoulder;
game_button_state Back;
game_button_state Start;
game_button_state Terminator;
};
};
} game_controller_input;
|
Error message:
| ./src/game_platform.h:168:9: error: anonymous structs are a GNU extension [-Werror,-Wgnu-anonymous-struct]
struct
^
./src/game_platform.h:168:9: error: anonymous types declared in an anonymous union are an extension [-Werror,-Wnested-anon-types]
|
Here's how I compile:
| /usr/bin/clang++ \
./src/main.cpp \
-g \
-Wall -Werror \
-pedantic \
-Wno-unused-variable -Wno-unused-function -Wno-deprecated-declarations \
-DGAME_INTERNAL=1 -DGAME_SLOW=1 \
-lsfml-window -lsfml-system -lsfml-graphics -lsfml-audio -lstdc++ \
-std=c++11 \
-o ./build/game
|
I did some research but found no way to make this work. In the end I've had to assign names to the union and the structure, which makes the code explicit, but clunky:
| osxProcessKeyUpDown(&keyboardController->game_buttons.button_states.MoveUp, isDown);
|
I also don't understand why the following vector definition works fine, which also an anonymous struct, if I understand correctly:
| union v2
{
struct
{
real32 X, Y;
};
real32 E[2];
};
|
I am an experienced engineer, but C is not my area of competence. One of the reasons I took up following this series is to increase and solidify my knowledge of C, maths, low-level programming and so on. My inability to figure this out is driving me crazy :)
I suspect that this is because I'm compiling in C++/11 but giving it up would mean abandoning features like function overload which are used in the code, right? Casey mentions on the recording of Day 42 that there were some reports on the issues with LLVM, but provides no solution.
Maybe he addresses the subject in later episodes, but I'd love to have it working right now before I move on.
I hope someone could shed some light on both subjects.
Thanks in advance.