Can you add more than one attribute to an identifier in C with gcc? Here is what I have now. I left out the include statements because they get scramble in the post. If there is a way to add two, what is the general syntax, and how can I do it both with the defintion, and with a prototype? Thank you. :-)
main() { printf("In Main\n"); } __attribute__ ((constructor)) void beforeMain(void) { printf("Before Main\n"); }
The __attribute__ directive is used to decorate a code declaration in C, C++ and Objective-C programming languages. This gives the declared code additional attributes that would help the compiler incorporate optimizations or elicit useful warnings to the consumer of that code.
A domain is a set of all possible values that a variable is allowed to have. The values are ordered in a logical way and must be defined for each variable. Domains can be bigger or smaller. The smallest possible domains have those variables that can only have two values, also called binary (or dichotomous) variables.
Master C and Embedded C Programming- Learn as you go Attributes are modern ways in C++ to standardize things if their code runs on different compilers. Attributes are used to provide some extra information that is used to enforce conditions (constraints), optimization and do specific code generation if required.
Attributes are a mechanism by which the developer can attach extra information to language entities with a generalized syntax, instead of introducing new syntactic constructs or keywords for each feature.
There are two different ways of specifying multiple attributes in C with GCC:
#include <stdio.h> // Attributes in prototypes: __attribute__((constructor, weak)) void beforeMain(void); __attribute__((constructor)) __attribute__((weak)) void beforeMain2(void); int main(){ printf("In Main\n"); return 0; } // Attributes in definitions: __attribute__((constructor, weak)) void beforeMain(void){ printf("Before Main 1\n"); } __attribute__((constructor)) __attribute__((weak)) void beforeMain2(void){ printf("Before Main 2\n"); }
The code above compiles and runs correctly for me under gcc version 4.4.3.
You can use multiple __attribute__ specifiers separated by spaces.
char s[3] __attribute__((aligned(32))) __attribute__((weak));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With