Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Irritating multiple redefinition problem -- please help |
| Date | 2015-09-14 16:41 +0100 |
| Organization | A noiseless patient Spider |
| Message-ID | <87egi1f1pu.fsf@bsb.me.uk> (permalink) |
| References | <d26a19b9-2aa7-451d-9df4-14ece63ad4a2@googlegroups.com> <d5mufiF884kU11@mid.individual.net> <mt6046$slc$1@dont-email.me> <mt6f5q$ftr$1@speranza.aioe.org> <mt6ite$1bb$1@dont-email.me> |
David Brown <david.brown@hesbynett.no> writes: > On 14/09/15 14:39, August Karlstrom wrote: >> On 2015-09-14 10:24, David Brown wrote: >>> On 14/09/15 05:50, Ian Collins wrote: >>>> Make the declaration in the header >>>> >>>> extern const double PI2; >>>> >>>> and define in in one and only one .c file >>>> >>>> const double PI2 = 6.28; >>>> >>> >>> Alternatively, especially for simple constants, change the declaration >>> in the header file to the definition : >>> >>> static const double PI2 = 6.28; <snip> >> Why not simply >> >> #define PI2 6.28 > > Yes, that would work too in this case. But there is a general trend > that if something can be expressed as a typed constant value, rather > than a pre-process macro, then the const is to be preferred. It has > better type safety, can be scoped (not relevant in this case), is less > prone to accidents (because you can only use it in places where that > type is appropriate), and plays better with IDEs/editors and > debuggers. You mention twice safety twice, but 6.28 (the result of the #defined) has the same type as PI2 defined as a const double. The latter is an lvalue (though not a modifyable one) but that's probably not important. <snip> -- Ben.
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Irritating multiple redefinition problem -- please help dakupoto@gmail.com - 2015-09-13 20:39 -0700
Re: Irritating multiple redefinition problem -- please help Ian Collins <ian-news@hotmail.com> - 2015-09-14 15:50 +1200
Re: Irritating multiple redefinition problem -- please help David Brown <david.brown@hesbynett.no> - 2015-09-14 10:24 +0200
Re: Irritating multiple redefinition problem -- please help August Karlstrom <fusionfile@gmail.com> - 2015-09-14 14:39 +0200
Re: Irritating multiple redefinition problem -- please help David Brown <david.brown@hesbynett.no> - 2015-09-14 15:45 +0200
Re: Irritating multiple redefinition problem -- please help Richard Heathfield <rjh@cpax.org.uk> - 2015-09-14 14:52 +0100
Re: Irritating multiple redefinition problem -- please help August Karlstrom <fusionfile@gmail.com> - 2015-09-14 18:13 +0200
Re: Irritating multiple redefinition problem -- please help Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-09-14 16:41 +0100
Re: Irritating multiple redefinition problem -- please help dakupoto@gmail.com - 2015-09-14 19:47 -0700
Re: Irritating multiple redefinition problem -- please help Paul N <gw7rib@aol.com> - 2015-09-15 16:00 -0700
Re: Irritating multiple redefinition problem -- please help gordonb.78i5t@burditt.org (Gordon Burditt) - 2015-09-13 23:40 -0500
Re: Irritating multiple redefinition problem -- please help Ike Naar <ike@iceland.freeshell.org> - 2015-09-20 20:24 +0000
csiph-web