1 /* $NetBSD: gcc_attribute_var.c,v 1.13 2024/09/28 15:51:40 rillig Exp $ */ 2 # 3 "gcc_attribute_var.c" 3 4 /* 5 * Tests for the GCC __attribute__ for variables. 6 * 7 * https://gcc.gnu.org/onlinedocs/gcc/Variable-Attributes.html 8 */ 9 10 /* lint1-extra-flags: -X 351 */ 11 12 void 13 write_to_page(unsigned index, char ch) 14 { 15 static char page[4096] 16 __attribute__((__aligned__(4096))); 17 18 page[index] = ch; 19 } 20 21 void 22 placement( 23 __attribute__((__deprecated__)) int before, 24 int __attribute__((__deprecated__)) between, 25 int after __attribute__((__deprecated__)) 26 ); 27 28 void println(void); 29 30 /* 31 * A GCC extension allows statement of the form __attribute__((fallthrough)), 32 * therefore, to avoid shift/reduce conflicts in the grammar, the attributes 33 * cannot be part of the declaration specifiers between begin_type/end_type. 34 */ 35 void 36 ambiguity_for_attribute(void) 37 { 38 __attribute__((unused)) _Bool var1; 39 40 switch (1) { 41 case 1: 42 println(); 43 __attribute__((unused)) _Bool var2; 44 __attribute__((fallthrough)); 45 case 2: 46 println(); 47 } 48 } 49 50 void 51 attribute_after_array_brackets( 52 const char *argv[] __attribute__((__unused__)) 53 ) 54 { 55 } 56 57 struct attribute_in_member_declaration { 58 int __attribute__(()) 59 x __attribute__(()), 60 y __attribute__(()); 61 62 unsigned int __attribute__(()) 63 bit1:1 __attribute__(()), 64 bit2:2 __attribute__(()), 65 bit3:3 __attribute__(()); 66 }; 67 68 69 void 70 anonymous_members(void) 71 { 72 struct single_attribute_outer { 73 struct single_attribute_inner { 74 int member; 75 } __attribute__(()); 76 } __attribute__(()); 77 78 struct multiple_attributes_outer { 79 struct multiple_attributes_inner { 80 int member; 81 } __attribute__(()) __attribute__(()); 82 } __attribute__(()) __attribute__(()); 83 } 84