C: allergies

This commit is contained in:
2021-08-27 20:14:58 +02:00
parent 29905d7894
commit e45819d3ef
3 changed files with 9 additions and 2 deletions

View File

@@ -1,9 +1,11 @@
#include "allergies.h" #include "allergies.h"
#ifdef USE_ALLERGIC_TO_FUNCTION
bool is_allergic_to(const allergen_t all, const uint32_t val) bool is_allergic_to(const allergen_t all, const uint32_t val)
{ {
return !!(val & (1 << all)); return !!(val & (1 << all));
} }
#endif
allergen_list_t get_allergens(uint32_t val) allergen_list_t get_allergens(uint32_t val)
{ {

View File

@@ -21,9 +21,13 @@ typedef struct {
bool allergens[ALLERGEN_COUNT]; bool allergens[ALLERGEN_COUNT];
} allergen_list_t; } allergen_list_t;
// We could use macro... // We can choose macro or function
// #define is_allergic_to(allerg, val) (!!((val) & (1 << (allerg)))) #ifdef USE_ALLERGIC_TO_FUNCTION
bool is_allergic_to(const allergen_t allergen, const uint32_t value); bool is_allergic_to(const allergen_t allergen, const uint32_t value);
#else
#define is_allergic_to(allerg, val) (!!((val) & (1 << (allerg))))
#endif
allergen_list_t get_allergens(uint32_t value); allergen_list_t get_allergens(uint32_t value);
/* See GNUmakefile below for explanation /* See GNUmakefile below for explanation

View File

@@ -5,6 +5,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#endif #endif
#ifdef TESTALL #ifdef TESTALL
#undef TEST_IGNORE #undef TEST_IGNORE
#define TEST_IGNORE() {} #define TEST_IGNORE() {}