Skip to content

Instantly share code, notes, and snippets.

@jbrzozoski
Created March 11, 2020 15:33
Show Gist options
  • Save jbrzozoski/0db403c5ad3920411e41f6ee3b0c0152 to your computer and use it in GitHub Desktop.
Save jbrzozoski/0db403c5ad3920411e41f6ee3b0c0152 to your computer and use it in GitHub Desktop.
Example of indexed array declarations in c
#define ERROR_ALPHA 1
#define ERROR_BETA 4
#define ERROR_GAMMA 3
#define ERROR_DELTA 2
static const char *const strerr[] = {
[ERROR_ALPHA] = "Error Alpha",
[ERROR_BETA] = "Error Beta",
[ERROR_GAMMA] = "Error Gamma",
[ERROR_DELTA] = "Error Delta",
};
@jbrzozoski
Copy link
Author

Note that the order of the items in the array declaration don't have to match. I believe any gaps in the indexing should be initialized as if memclr().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment