Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #138476

Re: Multiple Includes Causing Multiple Definitions? (GCC 6.3.0) on Debian 9

From David Brown <david.brown@hesbynett.no>
Newsgroups comp.lang.c
Subject Re: Multiple Includes Causing Multiple Definitions? (GCC 6.3.0) on Debian 9
Date 2018-12-02 12:49 +0100
Organization A noiseless patient Spider
Message-ID <pu0gsb$nu3$1@dont-email.me> (permalink)
References (10 earlier) <oe700epcqp4k7ip9cu1889h3teso4hlttd@4ax.com> <t7f30epvh4vo7ohraiodejcr5hent0msph@4ax.com> <lnva4emayi.fsf@kst-u.example.com> <ptue79$ihr$1@dont-email.me> <uxAMD.650912$OM2.86636@fx37.iad>

Show all headers | View raw


On 01/12/2018 19:37, Richard Damon wrote:
> On 12/1/18 11:51 AM, David Brown wrote:
>> On 30/11/2018 23:56, Keith Thompson wrote:
>>> Geoff <geoff@invalid.invalid> writes:
>>>> On Fri, 30 Nov 2018 12:48:19 -0800, Geoff <geoff@invalid.invalid>
>>>> wrote:
>>>>
>>>>> If I can produce a simple project that reproduces this result I'll
>>>>> post it.
>>>>>
>>>>> Thanks for all the help.
>>>>
>>>> I found the error. One of the project headers, invoked by all the
>>>> modules had this at the very top:
>>>>
>>>> #define __attribute__ (x)
>>>>
>>>> This will probably hose over just about any implementation and I'm
>>>> surprised this problem didn't show up a long time ago. It sneaked into
>>>> the code somewhere between 2010 and 2013. I blame Obama. :-)
>>>
>>> I suspect it was actually
>>>
>>> #define __attribute__(x)
>>>
>>> without the space.  Normally __attribute__ (a common non-standard
>>> extension) takes a doubly parenthesized argument, such as __attribute__
>>> ((packed))
>>>
>>> The latter macro definition would remove all uses of __attribute__
>>> (which would of course break any code that depends on it).
>>>
>>
>> Most, but not all, uses of __attribute__ are not necessary for correct
>> code.  They improve optimisation, or error checking (such as checking
>> formats in printf-like functions, or marking parameters as non-null). So
>> often this define is with conditional compilation - if the compiler is
>> gcc (or a mostly compatible alternative, like clang), you get more
>> efficient code or better checking during development, and for other
>> compilers you get code without this extension.
> 
> I suppose most is a matter of opinion.

Yes - and of how you count them, and by the kind of code you write.

> I suspect my most used would be
> __attribute__((interrupt)) which definitively might make a difference
> between working and non-working code (except on the Cortex-M series
> where the hardware was defined to do what was needed automatically for
> ISRs).

Attributes like "interrupt" certainly do make a difference to how the 
code works.  Such code is rarely very portable, however.

> 
> The next most common is likely __attribute__((weak)) which if ignored
> would results in Undefined Behavior that tends to result in link errors.
> 
> You example of __attribute__((packed)) is another example where ignoring
> the option will often yield incorrect code if it is being used to make a
> structure to exactly match an externally defined structure that has
> fields not properly aligned for the processor being used.
> 
> Yes, some usages of __attribute__ are just hints, but in my mind
> #define __attribute__(x)
> is a sign of a quick fix being applied that may be hiding a bigger issue.
> 

Agreed.

My preference is to have things like:

	#define alwaysInline __attribute__((always_inline))

Then use the "alwaysInline" macro in the code, rather than using 
__attribute__ directly.  With this sort of abstraction, it is a lot 
easier to get portable code (at least, to make the bits that /can/ be 
portable, portable).

But /if/ you see the line "#define __attribute__(x)", it is usually for 
such making code acceptable to compilers other than gcc (or its 
friends).  It might be for a tool like doxygen, rather than another 
compiler.

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Multiple Includes Causing Multiple Definitions? (GCC 6.3.0) on Debian 9 Geoff <geoff@invalid.invalid> - 2018-11-27 14:38 -0800
  Re: Multiple Includes Causing Multiple Definitions? (GCC 6.3.0) on Debian 9 Ian Collins <ian-news@hotmail.com> - 2018-11-28 15:37 +1300
    Re: Multiple Includes Causing Multiple Definitions? (GCC 6.3.0) on Debian 9 Geoff <geoff@invalid.invalid> - 2018-11-27 19:53 -0800
      Re: Multiple Includes Causing Multiple Definitions? (GCC 6.3.0) on Debian 9 Ian Collins <ian-news@hotmail.com> - 2018-11-28 17:42 +1300
        Re: Multiple Includes Causing Multiple Definitions? (GCC 6.3.0) on Debian 9 Geoff <geoff@invalid.invalid> - 2018-11-27 22:06 -0800
          Re: Multiple Includes Causing Multiple Definitions? (GCC 6.3.0) on Debian 9 Ian Collins <ian-news@hotmail.com> - 2018-11-28 20:45 +1300
            Re: Multiple Includes Causing Multiple Definitions? (GCC 6.3.0) on Debian 9 Geoff <geoff@invalid.invalid> - 2018-11-28 10:30 -0800
              Re: Multiple Includes Causing Multiple Definitions? (GCC 6.3.0) on Debian 9 jameskuyper@alumni.caltech.edu - 2018-11-28 11:01 -0800
                Re: Multiple Includes Causing Multiple Definitions? (GCC 6.3.0) on Debian 9 Geoff <geoff@invalid.invalid> - 2018-11-29 01:35 -0800
                Re: Multiple Includes Causing Multiple Definitions? (GCC 6.3.0) on Debian 9 James Kuyper <jameskuyper@alumni.caltech.edu> - 2018-11-29 08:15 -0500
                Re: Multiple Includes Causing Multiple Definitions? (GCC 6.3.0) on Debian 9 Geoff <geoff@invalid.invalid> - 2018-11-30 12:48 -0800
                Re: Multiple Includes Causing Multiple Definitions? (GCC 6.3.0) on Debian 9 Geoff <geoff@invalid.invalid> - 2018-11-30 14:49 -0800
                Re: Multiple Includes Causing Multiple Definitions? (GCC 6.3.0) on Debian 9 Keith Thompson <kst-u@mib.org> - 2018-11-30 14:56 -0800
                Re: Multiple Includes Causing Multiple Definitions? (GCC 6.3.0) on Debian 9 Geoff <geoff@invalid.invalid> - 2018-11-30 15:46 -0800
                Re: Multiple Includes Causing Multiple Definitions? (GCC 6.3.0) on Debian 9 David Brown <david.brown@hesbynett.no> - 2018-12-01 17:51 +0100
                Re: Multiple Includes Causing Multiple Definitions? (GCC 6.3.0) on Debian 9 Richard Damon <Richard@Damon-Family.org> - 2018-12-01 13:37 -0500
                Re: Multiple Includes Causing Multiple Definitions? (GCC 6.3.0) on Debian 9 David Brown <david.brown@hesbynett.no> - 2018-12-02 12:49 +0100
                Re: Multiple Includes Causing Multiple Definitions? (GCC 6.3.0) on Debian 9 Richard Damon <Richard@Damon-Family.org> - 2018-12-02 08:16 -0500
                Re: Multiple Includes Causing Multiple Definitions? (GCC 6.3.0) on Debian 9 David Brown <david.brown@hesbynett.no> - 2018-12-02 14:45 +0100
                Re: Multiple Includes Causing Multiple Definitions? (GCC 6.3.0) on Debian 9 Geoff <geoff@invalid.invalid> - 2018-12-04 08:51 -0800
                Re: Multiple Includes Causing Multiple Definitions? (GCC 6.3.0) on Debian 9 scott@slp53.sl.home (Scott Lurndal) - 2018-12-04 17:16 +0000
                Re: Multiple Includes Causing Multiple Definitions? (GCC 6.3.0) on Debian 9 William Ahern <william@25thandClement.com> - 2018-12-04 12:26 -0800
                Re: Multiple Includes Causing Multiple Definitions? (GCC 6.3.0) on Debian 9 Geoff <geoff@invalid.invalid> - 2018-12-05 07:08 -0800
                Re: Multiple Includes Causing Multiple Definitions? (GCC 6.3.0) on Debian 9 William Ahern <william@25thandClement.com> - 2018-12-05 13:39 -0800
                Re: Multiple Includes Causing Multiple Definitions? (GCC 6.3.0) on Debian 9 Geoff <geoff@invalid.invalid> - 2018-12-05 20:25 -0800
                Re: Multiple Includes Causing Multiple Definitions? (GCC 6.3.0) on Debian 9 Tim Rentsch <txr@alumni.caltech.edu> - 2018-12-06 07:01 -0800
                Re: Multiple Includes Causing Multiple Definitions? (GCC 6.3.0) on Debian 9 Tim Rentsch <txr@alumni.caltech.edu> - 2018-11-29 10:26 -0800
                Re: Multiple Includes Causing Multiple Definitions? (GCC 6.3.0) on Debian 9 Geoff <geoff@invalid.invalid> - 2018-11-30 12:59 -0800
                Re: Multiple Includes Causing Multiple Definitions? (GCC 6.3.0) on Debian 9 Tim Rentsch <txr@alumni.caltech.edu> - 2018-12-01 07:23 -0800
                Re: Multiple Includes Causing Multiple Definitions? (GCC 6.3.0) on Debian 9 Tim Rentsch <txr@alumni.caltech.edu> - 2018-12-02 03:56 -0800
                Re: Multiple Includes Causing Multiple Definitions? (GCC 6.3.0) on Debian 9 Geoff <geoff@invalid.invalid> - 2018-12-02 08:10 -0800
                Re: Multiple Includes Causing Multiple Definitions? (GCC 6.3.0) on Debian 9 Tim Rentsch <txr@alumni.caltech.edu> - 2018-12-03 14:00 -0800
              Re: Multiple Includes Causing Multiple Definitions? (GCC 6.3.0) on Debian 9 Nick Bowler <nbowler@draconx.ca> - 2018-11-28 19:42 +0000
              Re: Multiple Includes Causing Multiple Definitions? (GCC 6.3.0) on Debian 9 Tim Rentsch <txr@alumni.caltech.edu> - 2018-11-29 10:09 -0800
          Re: Multiple Includes Causing Multiple Definitions? (GCC 6.3.0) on Debian 9 jameskuyper@alumni.caltech.edu - 2018-11-28 05:55 -0800
            Re: Multiple Includes Causing Multiple Definitions? (GCC 6.3.0) on Debian 9 Geoff <geoff@invalid.invalid> - 2018-11-28 10:36 -0800
  Re: Multiple Includes Causing Multiple Definitions? (GCC 6.3.0) on Debian 9 Bart <bc@freeuk.com> - 2018-11-28 13:13 +0000
    Re: Multiple Includes Causing Multiple Definitions? (GCC 6.3.0) on Debian 9 Geoff <geoff@invalid.invalid> - 2018-11-30 13:39 -0800

csiph-web