Skip to content

Invalid C code in game sdk starter guide #5986

Open
@bababooey1234

Description

@bababooey1234

Description

Following the game sdk getting started tutorial at https://discord.com/developers/docs/game-sdk/sdk-starter-guide#code-primer-unreal-engine-c raises the compilation error error: storage size of 'events' isn't known

The game sdk provides the following snippets for utilising the game sdk library in C:

#pragma pack(push, 8)
#include "discord_game_sdk.h"
#pragma pack(pop)
struct Application {
    struct IDiscordCore* core;
    struct IDiscordUsers* users;
};

struct Application app;
// Don't forget to memset or otherwise initialize your classes!
memset(&app, 0, sizeof(app));

struct IDiscordCoreEvents events;
memset(&events, 0, sizeof(events));

struct DiscordCreateParams params;
params.client_id = CLIENT_ID;
params.flags = DiscordCreateFlags_Default;
params.events = &events;
params.event_data = &app;

DiscordCreate(DISCORD_VERSION, &params, &app.core);

However, the line struct IDiscordCoreEvents events; raises the following compilation error in the TDM64-GCC compiler:

error: storage size of 'events' isn't known

This seems to be due to the fact that struct IDiscordCoreEvents is defined with typedef void* IDiscordCoreEvents; in discord_game_sdk.h, although I'm not sure why that would cause an error, as replacing the line in the code with void *events; seems to work just fine.

Steps to Reproduce

main.c:

#include <stdio.h>
#pragma pack(push, 8)
#include "c/discord_game_sdk.h"
#pragma pack(pop)

struct Application {
    struct IDiscordCore *core;
    struct IDiscordUsers *users;
};

int main(void) {
    struct Application app;
    memset(&app, 0, sizeof(app));

    struct IDiscordCoreEvents events;
    memset(&events, 0, sizeof(events));
    
    struct DiscordCreateParams params;
    DiscordCreateParamsSetDefault(&params);

    params.client_id = clientid;
    params.flags = DiscordCreateFlags_Default;
    params.events = &events;
    params.event_data = &app;

    enum EDiscordResult result = DiscordCreate(DISCORD_VERSION, &params, &app.core);

    if(result)exit(result);

    puts("Application Created");
}

Compile with: gcc -Wall -o main.exe -L -l discord_game_sdk.dll main.c (with discord_game_sdk.dll and discord_game_sdl.dll.lib in same directory as main.c)

Expected Behavior

Setup completing without error

Current Behavior

error: storage size of 'events' isn't known

Screenshots/Videos

No response

Client and System Information

Compiler: TDM64-GCC version 10.3.0

OS: Microsoft Windows 11 Home Version 10.0.22621 Build 22621

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions