AVR/GNU C++ Compiler - duplicate 'inline' error

Go To Last Post
10 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Disclaimer: I already know about the warning that ASF may not work well with C++ projects, everything I am using works with the exception of this.  I have -std=c++11 defined in other flags in the C++ miscellaneous tab.

 

Calling all compiler gurus. ;) 

 

In ASF/common/services/ioport/mega/ioport.h there are functions that are declared and defined like this:

__always_inline static inline function(...) {...}

This is not a problem for the AVR/GNU C compiler but it is for the AVR/GNU C++ compiler as it sees the "__always_inline" and the "inline" as duplicate and flags them as errors.

 

I have worked around this by removing the "inline" from the definitions.  Is doing so a problem?  Is there a compiler flag to ignore the duplicate error?  Can you explain why the C++ compiler has a problem with this?

 

EDIT: I guess what I am questioning is whether the "inline" following the "__always_inline" is superfluous or not. 

"I may make you feel but I can't make you think" - Jethro Tull - Thick As A Brick

"void transmigratus(void) {transmigratus();} // recursio infinitus" - larryvc

"It's much more practical to rely on the processing powers of the real debugger, i.e. the one between the keyboard and chair." - JW wek3

"When you arise in the morning think of what a privilege it is to be alive: to breathe, to think, to enjoy, to love." -  Marcus Aurelius

Last Edited: Sun. Jan 18, 2015 - 08:13 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I answered my own questions.  (Amazing what a little sleep can do.)

 

The macro definition of "__always_inline" in ASF\mega\utils\compiler.h explained the problem: 

#define __always_inline inline __attribute__((__always_inline__))  <- Added for completeness of example

__always_inline static inline function(...) {...}  which becomes

inline __attribute__((__always_inline__)) static inline function(...) {...} <- duplicate 'inline'

Now I will let Atmel know that they have a problem in their header files. frown  I will mark this thread as solved once I get an answer from Atmel.

"I may make you feel but I can't make you think" - Jethro Tull - Thick As A Brick

"void transmigratus(void) {transmigratus();} // recursio infinitus" - larryvc

"It's much more practical to rely on the processing powers of the real debugger, i.e. the one between the keyboard and chair." - JW wek3

"When you arise in the morning think of what a privilege it is to be alive: to breathe, to think, to enjoy, to love." -  Marcus Aurelius

Last Edited: Sun. Jan 18, 2015 - 06:53 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Does the attribute __always_inline__ make inline redundant?

Iluvatar is the better part of Valar.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

skeeve wrote:
Does the attribute __always_inline__ make inline redundant?

That is the real answer that I am looking for and so far haven't found.  If it is, then the remaining "inline" in the function definitions would indeed be superfluous, that is if I got the correct meaning of your question.

 

inline __attribute__((__always_inline__)) static inline function(...) {...} <- Is the inline here superfluous since we already have the attribute "always_inline__"?

 

"I may make you feel but I can't make you think" - Jethro Tull - Thick As A Brick

"void transmigratus(void) {transmigratus();} // recursio infinitus" - larryvc

"It's much more practical to rely on the processing powers of the real debugger, i.e. the one between the keyboard and chair." - JW wek3

"When you arise in the morning think of what a privilege it is to be alive: to breathe, to think, to enjoy, to love." -  Marcus Aurelius

Last Edited: Sun. Jan 18, 2015 - 08:37 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

skeeve wrote:

Does the attribute __always_inline__ make inline redundant?

No, there is a least one difference (that I rely on (or abuse) in my code). Without "inline" the compiler (at least all the versions that I used so far) complain about "defined but not used" function.

Last Edited: Sun. Jan 18, 2015 - 08:39 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ezharkov wrote:

 

skeeve wrote:

Does the attribute __always_inline__ make inline redundant?

 

No, there is a least one difference (that I rely on (or abuse) in my code). Without "inline" the compiler (at least all the versions that I used so far) complain about "defined but not used" function.

Thanks, that seems to concur with the results of the testing that I have just done.  I would like to hear more on the details regarding "rely on (or abuse)".  What do you use it for? 

"I may make you feel but I can't make you think" - Jethro Tull - Thick As A Brick

"void transmigratus(void) {transmigratus();} // recursio infinitus" - larryvc

"It's much more practical to rely on the processing powers of the real debugger, i.e. the one between the keyboard and chair." - JW wek3

"When you arise in the morning think of what a privilege it is to be alive: to breathe, to think, to enjoy, to love." -  Marcus Aurelius

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

larryvc wrote:

What do you use it for? 

I usually want the compiler to complain about (pretty much) all unused functions, even those defined as "static inline". For that, I define them as "static __attribute__((always_inline))" rather than "static inline". (Occasionally I do have functions that I don't want the compiler to complain about. Then I define them as "static inline __attribute__((always_inline))". Or just "static inline", if I don't care about the inline-ness guarantee.)

Last Edited: Sun. Jan 18, 2015 - 10:45 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Larry,

 

could you please send me an example of C++ + ASF project which compiles and links fine? I am using Atmel Studio 7 a and SAM4E Xplained Pro kit, but cannot get even a plain sample C++ project with ASF board support package. I am getting this  error :

Severity Code Description Project File Line

Error 'CKGR_MOR_KEY_PASSWD' undeclared (first use in this function) GccApplication2 C:\Projects\Atmel\GccApplication2\GccApplication2\src\ASF\sam\utils\cmsis\sam4e\source\templates\system_sam4e.c 66

 

thanks

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

@fkaudch: Stop hijacking threads on subjects unrelated to the problem you have. Please.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

...and Larry hasn't been around for a long time, hope he is OK, maybe driving around Europe in some Lamborghini or other bucket of rust.....

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly