Replace include guards with #pragma once#1703
Replace include guards with #pragma once#1703mossmann merged 2 commits intogreatscottgadgets:mainfrom
#pragma once#1703Conversation
5d87596 to
7349f09
Compare
7349f09 to
000d2e8
Compare
564d8f5 to
66172a9
Compare
|
#pragma once tells the compiler "only include this file once", but the compiler has to figure out what "this file" means. It typically does that using the file's path or inode. |
If you have two headers with the same name, in directories that are both in the compiler's list of include paths, like To include both #include <a/api.h>
#include <b/api.h>In which case, it's pretty clear that you're actually intentionally including both headers.
That's actually exactly the problem with them. Because there's no guaranteed way to uniquely name them, it's quite likely that if In fact, this is exactly the scenario that led me to ask @antoinevg for this change. I was working on our Portapack firmware project that @mossmann mentioned in portapack-mayhem/mayhem-firmware#2957 (comment), and I ended up needing to include both This is where
The main issue with |
66172a9 to
5a4ddfb
Compare
| void delay_us_at_mhz(uint32_t us, uint32_t mhz); | ||
|
|
||
| #endif /* __DELAY_H */ | ||
| #ifdef __cplusplus |
No offenses intended. But, from the very same article you are mentioning, carefully read the caveats section. Maybe my case is not everyone's case, I'm working on legacies code bases on servers, with lots of symlinks and source files copies. I did not choose that, I inherited that and fix as I can. And pragma got our asses more than one time. I guess for hackRF code it's ok, but it's not the best move ever, from my point of view. I'm surely getting old, at least for code opinions and view points.... |
martinling
left a comment
There was a problem hiding this comment.
This is missing the same change in the recently-added da7219.h.
5a4ddfb to
976f91d
Compare
Whoopsie tx! Fixed and force-pushed. |
976f91d to
5f8601b
Compare
None taken!
I have read that, and the claim that Are you able to describe a specific scenario that may cause a problem - with compilers from the last 20 years? I've been doing a bit of research about this, because it's been feeling to me like " What I've found is that support for it was first added to GCC in 2001 in the venerable 2.95 release, but with a buggy implementation which would sometimes get confused and include things twice. In 2003, it was deprecated and slated for removal, both due to that bug, and the fact it was not yet standardised. However, the implementation was then fixed in 2004, released in version 3.4 and the deprecation removed. I've yet to find anything definitive that suggests it's been an actual problem since! |
Depends on #1701
This PR removes include guards in the style of:
…and replaces them with:
#pragma once ...