Created
December 6, 2017 20:41
-
-
Save lierdakil/e4b1e2dd6d312643c109eb8af89c97a1 to your computer and use it in GitHub Desktop.
Example of C concatenating macros
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
| #define AMACROS(id, size) \ | |
| static BIN_ATTR_RW(eeprom, size); \ | |
| static struct bin_attribute *w1_f ## id ## _bin_attrs[] = { \ | |
| &bin_attr_eeprom, \ | |
| NULL, \ | |
| }; \ | |
| static const struct attribute_group w1_f ## id ## _group = { \ | |
| .bin_attrs = w1_f ## id ## _bin_attrs, \ | |
| }; \ | |
| static const struct attribute_group *w1_f ## id ## _groups[] = { \ | |
| &w1_f ## id ## _group, \ | |
| NULL, \ | |
| }; \ | |
| static struct w1_family_ops w1_f ## id ## _fops = { \ | |
| .groups = w1_f ## id ## _groups, \ | |
| }; \ | |
| static struct w1_family w1_family_ ## id = { \ | |
| .fid = W1_EEPROM_DS2431, \ | |
| .fops = &w1_f ## id ## _fops, \ | |
| }; \ | |
| module_w1_family(w1_family_ ## id); | |
| // usage | |
| AMACROS(2d, W1_F2D_EEPROM_SIZE); | |
| AMACROS(a0, W1_FA0_EEPROM_SIZE); | |
| // output | |
| static BIN_ATTR_RW(eeprom, W1_F2D_EEPROM_SIZE); | |
| static struct bin_attribute *w1_f2d_bin_attrs[] = { &bin_attr_eeprom, NULL, }; | |
| static const struct attribute_group w1_f2d_group = { .bin_attrs = w1_f2d_bin_attrs, }; | |
| static const struct attribute_group *w1_f2d_groups[] = { &w1_f2d_group, NULL, }; | |
| static struct w1_family_ops w1_f2d_fops = { .groups = w1_f2d_groups, }; | |
| static struct w1_family w1_family_2d = { .fid = W1_EEPROM_DS2431, .fops = &w1_f2d_fops, }; | |
| module_w1_family(w1_family_2d); | |
| static BIN_ATTR_RW(eeprom, W1_FA0_EEPROM_SIZE); | |
| static struct bin_attribute *w1_fa0_bin_attrs[] = { &bin_attr_eeprom, NULL, }; | |
| static const struct attribute_group w1_fa0_group = { .bin_attrs = w1_fa0_bin_attrs, }; | |
| static const struct attribute_group *w1_fa0_groups[] = { &w1_fa0_group, NULL, }; | |
| static struct w1_family_ops w1_fa0_fops = { .groups = w1_fa0_groups, }; | |
| static struct w1_family w1_family_a0 = { .fid = W1_EEPROM_DS2431, .fops = &w1_fa0_fops, }; | |
| module_w1_family(w1_family_a0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment