2

I have noticed that I wrote by mistake

#include <vector>> //Notice the additional > after <vector>

My code compiled well without any problem. How is this possible?

P.S. I am on MSVS 2015

Edit:

The compiler actually raise a warning about it. However, should not it be an error rather than an warning by the standard?

Humam Helfawi
  • 19,566
  • 15
  • 85
  • 160
  • 1
    GCC and Clang also accept this code, with a warning. – Oktalist Nov 26 '16 at 20:37
  • 1>c:\users\starl1ght\documents\visual studio 2015\projects\stack\stack\main.cpp(5): warning C4067: unexpected tokens following preprocessor directive - expected a newline – Starl1ght Nov 26 '16 at 20:38
  • Sorry I did notice the warning.. but shouldn't it be an error? does the standard allow to write whatever after the include statement ? – Humam Helfawi Nov 26 '16 at 20:39
  • It's ill-formed according to the standard (as best as I can tell), but that's not your question. – krzaq Nov 26 '16 at 20:40
  • 6
    The standard doesn't make a difference between an error and a warning, it just says that [the compiler must issue a diagnostic](http://stackoverflow.com/questions/40807404/does-the-c-standard-specify-that-for-some-cases-the-compiling-should-fail-with). – Bo Persson Nov 26 '16 at 20:52
  • @BoPersson got it now.. thanks – Humam Helfawi Nov 26 '16 at 21:00
  • Apparently you can write anything after preprocessor directive and the compiler will only issue warning. – Barmak Shemirani Nov 26 '16 at 21:09
  • 1
    do you still remember the old days of visual c++ 6.0 where we can write: `??=include<>` instead of `#include<>`? – Raindrop7 Nov 26 '16 at 21:20
  • 2
    @Raindrop7: the `??=` is a trigraph for `#`. You can also use `%:` as a digraph for `#`. AFAIK, even C++14 hasn't eliminated trigraphs, but C++17 will. GCC doesn't recognize them unless you insist (`--trigraphs`). – Jonathan Leffler Nov 26 '16 at 22:13

0 Answers0