Error Attributes Are Not Allowed On A Function-definition
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us gcc attributes are not allowed on a function-definition Learn more about Stack Overflow the company Business Learn more about hiring developers or
Error Function Definition Is Not Allowed Here
posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow gcc disable inlining Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up gcc attributes with C++ methods up vote 6 gcc noinline down vote favorite In GCC with a C++ method defined in a header file, is it possible to use the attribute syntax? Can someone provide an example for me please. The following code does not work: class foo { public: void my_func() __attribute__((hot)); void my_func() { // Some stuff } }; It seems like you have to put the attributes in the declaration and not in the definition of a function. When you define a method/function in a header file you don't have a separate declaration. Also how to use this with templates. For example the following code fails to compile with 'error: attributes are not allowed on a function-definition'. /// Template version of max for type T template inline T max(const T x, const T y) __attribute((const)) { if (x > y) return x; else return y; } c++ gcc powerpc share|improve this question edited Jan 23 '14 at 0:30 NULL 290112 asked Jan 14 '14 at 14:39 ShaneCook 1559 1 Maybe because of the two trailing underscores? Try just __attribute__((hot)) instead. –Joachim Pileborg Jan 14 '14 at 14:44 Compile C++ with a C++ compiler (g++) and C with a C compiler (gcc). –Ed Heal Jan 14 '14 at 14:44 2 @EdHeal I think the OP means GCC as in the GNU Compiler Collection, and not as in the program gcc. –Joachim Pileborg Jan 14 '14 at 14:45 The tag wiki excerpt is unfortunately confusing on this one. It says both that gcc is the GNU Compiler Collection, and that it's the C compiler. –Philip Kendall Jan 14 '
always_inline and attribute placement on functions From: Jonathan Wakely To: gcc-help Date: Thu, 5 Sep 2013 13:43:58 +0100 Subject: always_inline and attribute placement on functions Authentication-results: sourceware.org; auth=none This is a sort of http://stackoverflow.com/questions/21116270/gcc-attributes-with-c-methods follow-up to http://gcc.gnu.org/ml/gcc-help/2007-01/msg00049.html The docs for the always_inline attribute at http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html say: "For functions declared inline, this attribute inlines the function even if no optimization level is specified." But testing and Ian's mail at http://gcc.gnu.org/ml/gcc-help/2007-01/msg00051.html say that you https://gcc.gnu.org/ml/gcc-help/2013-09/msg00019.html don't need the "inline" keyword on an "always_inline" function. Should the docs be clarified? For this code: $ cat b.cc inline void f() __attribute((always_inline)) { } $ g++ -std=gnu++0x b.cc -Wall -c -O3 b.cc:1:17: error: attributes are not allowed on a function-definition $ However, moving the attribute shows that actually it is allowed: $ cat b.cc inline __attribute((always_inline)) void f() { } $ g++ -std=gnu++0x b.cc -Wall -c -O3 $ If placing the attribute at that location is valid then the wording of the diagnostic is misleading, at best. Follow-Ups: Re: always_inline and attribute placement on functions From: Chung-Ju Wu Index Nav: [DateIndex] [SubjectIndex] [AuthorIndex] [ThreadIndex] Message Nav: [DatePrev][DateNext] [ThreadPrev][ThreadNext]
que nous obtenions votre permission avant d'envoyer des cookies à not allowed votre navigateur Web.Notre site dépend de ces cookies pour fonctionner correctement.Si vous souhaitez continuer vers le site, attributes are not nous supposerons que vous acceptez notre utilisation des cookies pour le bon fonctionnement de notre site et pour des publicités ciblées en fonction de vos intérêts. Pour en savoir plus, veuillez cliquer sur « Préférences de cookies » ci-dessous afin de définir vos préférences de cookies.Continuer vers le site