Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #150242
| From | David Brown <david.brown@hesbynett.no> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Concerning the necessity of include guards |
| Date | 2020-02-25 18:33 +0100 |
| Organization | A noiseless patient Spider |
| Message-ID | <r33lol$c6$1@dont-email.me> (permalink) |
| References | (6 earlier) <r32hdn$7nq$1@news.albasani.net> <r32nep$k8r$1@dont-email.me> <r32ppe$o9a$1@news.albasani.net> <r3331v$ij9$1@dont-email.me> <r3357h$1kn$1@news.albasani.net> |
On 25/02/2020 13:50, Bonita Montero wrote: >> I have used "exotic compilers" regularly over the years - as have a good >> many people in this group. I have maybe 10-15 different C compilers >> installed on my machines, not counting different versions. A couple >> were bought on 5¼" floppies. I don't use the older ones much, but >> occasionally I need to maintain ancient projects - I keep them all >> available. > > Maybe years ago, but today almost any compiler supports #pragma once. > You really have no idea, do you? Most C programmers use one of the major compilers (which, as Wikipedia says and you accept without any personal experience, support "pragma once"). Most C compilers, on the other hand, probably don't support it. That will include C compilers written or bought /today/ as well. Most C compilers are small, niche products for unusual targets or unusual needs. >> "Pragma once" is, at most, marginally more convenient than an include >> guard - .. > > With #pragma once theres no need to preprocess-parse the header for an > #endif, so compiling is faster. Big, serious compilers have particularly fast handling of include guards, and will not pre-process the file beyond matching up the #endif. For #pragma once, the compiler has to make sure it is dealing with the same file - depending on how that is determined (since it can be handled in many ways - there is no standard here) that can mean generating and comparing hashes for the files. It is unlikely that you will get any measurable difference either way. The exception, perhaps, is MSVC - which (AFAIUI) handles "pragma once" measurably faster than include guards. And even there I think this only applies to older versions of the compiler, meaning there is even less point is using non-standard and unreliable #pragma once. (In practice, speed issues only apply to C++, since C headers are generally too small to be relevant in the timing.) > >> guard - and comes with much vaguer semantics and lower portability. If >> MSVC (where "pragma once" is apparently noticeably faster than include >> guards) is all you ever see ... > > https://en.wikipedia.org/wiki/Pragma_once#Portability Yes, I have seen it. It covers a tiny fraction of the C compilers that people use (though it does cover the compilers that a large fraction of C programmers use). But even if it is supported by the compiler, why use it? Include guards are simple, standard, well-defined and efficient.
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Concerning the necessity of include guards Anton Shepelev <anton.txt@gmail.com> - 2020-02-24 22:08 +0300
Re: Concerning the necessity of include guards Bonita Montero <Bonita.Montero@gmail.com> - 2020-02-24 20:28 +0100
Re: Concerning the necessity of include guards Ben Bacarisse <ben.usenet@bsb.me.uk> - 2020-02-24 19:40 +0000
Re: Concerning the necessity of include guards David Brown <david.brown@hesbynett.no> - 2020-02-24 22:37 +0100
Re: Concerning the necessity of include guards Anton Shepelev <anton.txt@g{oogle}mail.com> - 2020-02-25 14:13 +0300
Re: Concerning the necessity of include guards David Brown <david.brown@hesbynett.no> - 2020-02-25 13:03 +0100
Re: Concerning the necessity of include guards Anton Shepelev <anton.txt@gmail.com> - 2020-02-29 01:14 +0300
Re: Concerning the necessity of include guards Bart <bc@freeuk.com> - 2020-02-28 22:36 +0000
Re: Concerning the necessity of include guards Anton Shepelev <anton.txt@gmail.com> - 2020-02-29 13:28 +0300
Re: Concerning the necessity of include guards Jorgen Grahn <grahn+nntp@snipabacken.se> - 2020-02-29 00:08 +0000
Re: Concerning the necessity of include guards Richard Damon <Richard@Damon-Family.org> - 2020-02-29 07:05 -0500
Re: Concerning the necessity of include guards David Brown <david.brown@hesbynett.no> - 2020-03-01 15:01 +0100
Re: Concerning the necessity of include guards Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2020-02-24 14:52 -0500
Re: Concerning the necessity of include guards Bonita Montero <Bonita.Montero@gmail.com> - 2020-02-24 21:19 +0100
Re: Concerning the necessity of include guards Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2020-02-24 15:48 -0500
Re: Concerning the necessity of include guards Bonita Montero <Bonita.Montero@gmail.com> - 2020-02-24 21:53 +0100
Re: Concerning the necessity of include guards Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2020-02-24 17:26 -0500
Re: Concerning the necessity of include guards David Brown <david.brown@hesbynett.no> - 2020-02-25 00:08 +0100
Re: Concerning the necessity of include guards Thiago Adams <thiago.adams@gmail.com> - 2020-02-24 15:24 -0800
Re: Concerning the necessity of include guards Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-02-24 22:20 -0800
Re: Concerning the necessity of include guards David Brown <david.brown@hesbynett.no> - 2020-02-25 09:52 +0100
Re: Concerning the necessity of include guards Bonita Montero <Bonita.Montero@gmail.com> - 2020-02-25 08:12 +0100
Re: Concerning the necessity of include guards David Brown <david.brown@hesbynett.no> - 2020-02-25 09:55 +0100
Re: Concerning the necessity of include guards Bonita Montero <Bonita.Montero@gmail.com> - 2020-02-25 10:35 +0100
Re: Concerning the necessity of include guards David Brown <david.brown@hesbynett.no> - 2020-02-25 13:13 +0100
Re: Concerning the necessity of include guards Bonita Montero <Bonita.Montero@gmail.com> - 2020-02-25 13:50 +0100
Re: Concerning the necessity of include guards David Brown <david.brown@hesbynett.no> - 2020-02-25 18:33 +0100
Re: Concerning the necessity of include guards Bonita Montero <Bonita.Montero@gmail.com> - 2020-02-25 18:38 +0100
Re: Concerning the necessity of include guards David Brown <david.brown@hesbynett.no> - 2020-02-25 18:42 +0100
Re: Concerning the necessity of include guards Bonita Montero <Bonita.Montero@gmail.com> - 2020-02-25 18:46 +0100
Re: Concerning the necessity of include guards Bart <bc@freeuk.com> - 2020-02-25 19:35 +0000
Re: Concerning the necessity of include guards David Brown <david.brown@hesbynett.no> - 2020-02-25 21:18 +0100
Re: Concerning the necessity of include guards Bonita Montero <Bonita.Montero@gmail.com> - 2020-02-26 06:40 +0100
Re: Concerning the necessity of include guards James Kuyper <jameskuyper@alumni.caltech.edu> - 2020-02-25 12:12 -0800
Re: Concerning the necessity of include guards James Kuyper <jameskuyper@alumni.caltech.edu> - 2020-02-25 11:55 -0800
Re: Concerning the necessity of include guards David Brown <david.brown@hesbynett.no> - 2020-02-25 21:37 +0100
Re: Concerning the necessity of include guards scott@slp53.sl.home (Scott Lurndal) - 2020-02-26 02:39 +0000
Re: Concerning the necessity of include guards Real Troll <real.troll@trolls.com> - 2020-02-25 23:10 -0400
Re: Concerning the necessity of include guards chad <cdalten@gmail.com> - 2020-02-27 05:39 -0800
Re: Concerning the necessity of include guards Jorgen Grahn <grahn+nntp@snipabacken.se> - 2020-02-24 22:23 +0000
Re: Concerning the necessity of include guards Tim Rentsch <tr.17687@z991.linuxsc.com> - 2020-02-24 21:17 -0800
Re: Concerning the necessity of include guards Guillaume <message@bottle.org> - 2020-02-25 13:03 +0100
csiph-web