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


Groups > comp.lang.c > #138481

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 14:45 +0100
Organization A noiseless patient Spider
Message-ID <pu0nlp$dip$1@dont-email.me> (permalink)
References (12 earlier) <lnva4emayi.fsf@kst-u.example.com> <ptue79$ihr$1@dont-email.me> <uxAMD.650912$OM2.86636@fx37.iad> <pu0gsb$nu3$1@dont-email.me> <RWQMD.614767$oM2.282289@fx07.iad>

Show all headers | View raw


On 02/12/2018 14:16, Richard Damon wrote:
> On 12/2/18 6:49 AM, David Brown wrote:
>> On 01/12/2018 19:37, Richard Damon wrote:
<snip>
>>> 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.
> 
> Yes, creating defines for particular attributes makes things more
> portable, and then you can have a header that defines them based on the
> detected compiler. Something like:
> 
> #if defined(GCC)
> #define ALWAYS_INLINE __attribute__((always_inline))
> #elif define(OTHER_CC)
> #define ALWAYS_INLINE
> #else
> #error Unknow Compiler
> #endif
> 
> (I use all caps for macros, and always add the else #error case to catch
> that problem)

Yes, that's the way to do it.  Often I know my code is not going to be 
very portable (at least in parts), and that portability is simply not a 
concern.  So then it's enough to write:

#ifndef __GNUC__
#error This code has only been tested with gcc!
#endif

Still, I keep the defines for attributes because it makes any future 
porting easier (there's a difference between making code that is 
portable, and making code that can be ported), and can make the code 
clearer.  And even if you don't want to use a different compiler with 
the code, you might still want to use doxygen or other tools.

(I know all-caps is traditional for preprocessor macros, but I am not a 
big fan of them.  I use all-caps in cases where it is vital to know that 
you have a macro - such as for avoiding "x = MAX(y++, foo());" - and for 
macros defined on the command line.)

> 
> I will still say that for code that didn't do this, blanket removal with
> a #define is likely going to produce non-working (even if it gives a
> clean compile) code.
> 
> For tools like Doxygen, you can either conditionally define it based on
> this being a Doxygen run, or put that definition in the Doxygen config.
> Putting it as a bare #define that other systems will see is still wrong.
> 

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