0

When using "g++" to compile some code, I can, for example, use types like "int32_t" (instead of "std::int32_t") or functions like "memcpy(...)" (instead of "std::memcpy(...)").

Is there a way to have the use of the namespace (or a "using namespace" statement) enforced by the compiler?

Thanks a lot for your answers.

no.human.being
  • 365
  • 3
  • 9
  • I'm not sure but you do not want to do this. Importing in all of `std` when you can use a couple `using std::whatever;` is not the way to go. Also see: [Why is “using namespace std;” considered bad practice?](http://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice) – NathanOliver Feb 09 '16 at 16:09
  • 1
    I believe he wants to *prevent* gcc from putting the names in the global namespace. So pretty much the opposite of `using namespace std;`. – Baum mit Augen Feb 09 '16 at 16:10
  • @NathanOliver I think you misunderstood my question. I do **not** want to have the entire "std::" namespace available but I have it (even if I do not specify any "using" statement). The compiler is a lot more sloppy than I'd like to have it. – no.human.being Feb 09 '16 at 16:11
  • 2
    The standard leaves it "unspecified" whether an inclusion of `` also puts the names from `` in the global namespace... – Kerrek SB Feb 09 '16 at 16:12
  • 2
    @juanchopanza He wants `int32_t i = 5;` to be a compiler error unless `using namespace std;` was used beforehand. – Baum mit Augen Feb 09 '16 at 16:12
  • @juanchopanza I want the compiler to require me to use the fully qualified name unless I "import" something from that namespace with a "using" statement. – no.human.being Feb 09 '16 at 16:12
  • @BaummitAugen Exactly. Or at least a warning. An error would actually be appropriate though, in my opinion. – no.human.being Feb 09 '16 at 16:13
  • 1
    @no.human.being OK, then unfortunately you can't, at least when if comes to names with equivalents in C header files (see Kerrek SB's comment.) It is annoying, but that's the way it is. – juanchopanza Feb 09 '16 at 16:13
  • @juanchopanza I understand. Thanks! – no.human.being Feb 09 '16 at 16:13
  • [Also relevant](https://gcc.gnu.org/bugzilla/show_bug.cgi?id=6257). – Baum mit Augen Feb 09 '16 at 16:19

0 Answers0