Created
October 7, 2018 19:42
-
-
Save elieux/3ee7a0073ce166aa4da9342e6840a93d to your computer and use it in GitHub Desktop.
libweek - something like an enum, but with values not known in the source code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <libweek.h> | |
static char* boolstr(bool b) { | |
return b ? "weekend, yay" : "a weekday"; | |
} | |
int main() { | |
printf("Monday (%d) is %s.\n", MONDAY, boolstr(is_weekend(MONDAY))); | |
printf("Tuesday (%d) is %s.\n", TUESDAY, boolstr(is_weekend(TUESDAY))); | |
printf("Wednesday (%d) is %s.\n", WEDNESDAY, boolstr(is_weekend(WEDNESDAY))); | |
printf("Thursday (%d) is %s.\n", THURSDAY, boolstr(is_weekend(THURSDAY))); | |
printf("Friday (%d) is %s.\n", FRIDAY, boolstr(is_weekend(FRIDAY))); | |
printf("Saturday (%d) is %s.\n", SATURDAY, boolstr(is_weekend(SATURDAY))); | |
printf("Sunday (%d) is %s.\n", SUNDAY, boolstr(is_weekend(SUNDAY))); | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "libweek.h" | |
const day_t MONDAY = 45; | |
const day_t TUESDAY = 84; | |
const day_t WEDNESDAY = 63; | |
const day_t THURSDAY = 37; | |
const day_t FRIDAY = 99; | |
const day_t SATURDAY = 102; | |
const day_t SUNDAY = 111; | |
bool is_weekend(day_t day) { | |
return day == SATURDAY || day == SUNDAY; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdbool.h> | |
typedef int day_t; | |
extern const day_t MONDAY; | |
extern const day_t TUESDAY; | |
extern const day_t WEDNESDAY; | |
extern const day_t THURSDAY; | |
extern const day_t FRIDAY; | |
extern const day_t SATURDAY; | |
extern const day_t SUNDAY; | |
bool is_weekend(day_t day); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
all: | |
gcc -Wall -Wextra -Werror -std=c99 -shared libweek.c -o libweek.dll | |
gcc -Wall -Wextra -Werror -std=c99 -L. -I. app.c -o app.exe -lweek |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment