Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix all struct names to be consistent with the agreed upon style guide. #235

Open
Tracked by #220
luckytyphlosion opened this issue Aug 22, 2023 · 2 comments
Open
Tracked by #220
Labels

Comments

@luckytyphlosion
Copy link
Member

There are still some style directions relating to structs which have no consensus. Those can be found at issue #212

1. All structs must have a corresponding typedef. The typedef must be defined with the struct.

See issue #212 point 5 for recursive/self-referential/"references each other" structs.

  • Good:
typedef struct BattleCursor {
    void *unk0[5];
    SysTask *task;
} BattleCursor;

Opaque struct declaration (only okay if the corresponding file isn't decompiled yet)

typedef struct GameStats GameStats;
  • Bad:

Missing corresponding typedef.

struct BattleCursor {
    void *unk0[5];
    SysTask *task;
};

Same as above but for opaque struct declaration.

struct GameStats;

Corresponding typedef is separate from struct definition.

struct BattleCursor {
    void *unk0[5];
    SysTask *task;
};
typedef struct BattleCursor BattleCursor;

struct must be defined as well as the typedef.

typedef struct {
    void *unk0[5];
    SysTask *task;
} BattleCursor;

2. Refer to the typedef in code, not the struct

  • Good:
const HiddenItemData *table = sHiddenItemParam;
  • Bad:
const struct HiddenItemData *table = sHiddenItemParam;

3. Struct names must match the typedef struct name

  • Good:
typedef struct HeapParam {
    u32 size;         // maximum size of the heap
    OSArenaId arena;  // where to allocate the heap from
} HeapParam;
  • Bad:
typedef struct HeapParam {
    u32 size;         // maximum size of the heap
    OSArenaId arena;  // where to allocate the heap from
} HeapParam_t; // _t suffix

4. Struct names and typedef struct names must be PascalCase

  • Good:
typedef struct WildEncounter {
    int state;
    int effect;
    int bgm;
    int *winFlag;
    BattleSetup *setup;
} WildEncounter;
  • Bad:
//  using ALL_CAPS instead of PascalCase
typedef struct WILD_ENCOUNTER {
    int state;
    int effect;
    int bgm;
    int *winFlag;
    BATTLE_SETUP *setup;
} WILD_ENCOUNTER;
Copy link

This issue has had no activity for 60 days and will be marked stale. If there is no further activity, it will be closed in 30 days.

Copy link

github-actions bot commented Nov 1, 2024

This issue has had no activity for 60 days and will be marked stale. If there is no further activity, it will be closed in 30 days.

@github-actions github-actions bot added the stale label Nov 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants