0

Here's an example:

cout<<"Hello There "<<
cout<<"How are you?"<<endl;

Should not compile with gcc but does on Mac. What's even stranger is that if you removed the last << on the first line, the compiler does pick up on the problem of the lack of a semi-colon.

If you add a line of code in between those above lines, be it a declaration, assignment, if, or loop, then it will not compile.

Program runs normally with the error not picked up. If I went to Linux, it doesn't compile.

If you invoke a particular version of C++ on the command-line, then it does pick up that there is an error.

Could the issue be related to the MacOS' use of clang?

I'm trying to understand what the difference would be on a Mac/MacOS between the following two command-line invocations:

g++ -o derp derp.cpp - compiles, then when I run it, it does its thing correctly. g++ -std=c++20 -o derp derp.cpp - will not compile

  • 2
    `cout<<"Hello There "< –  Feb 17 '23 at 21:17
  • 3
    [See this](https://stackoverflow.com/questions/10987156/does-stdcout-have-a-return-value#:~:text=cout%20does%20not%20have%20a,an%20object%20of%20type%20ostream%20.). Essentially, your example is the one-line example given by @YvesDaoust – PaulMcKenzie Feb 17 '23 at 21:20
  • In clicking the link that took me to another link, it says that cout< – baseballphd420 Feb 17 '23 at 21:59
  • Clang defaults to c++03, I'm guessing that's what you're using – Alan Birtles Feb 17 '23 at 22:01
  • @baseballphd420 Think about what you wrote: *"[X] was acceptable up until C++ 2011. It should be a compilation error with later versions."* -- In other words, if the code compiles, then the version is before C++11 -- *"Why does this not occur with at least on MacOS, unless you specify a version?"* -- In other words (dropping the question), if you do not specify a version, then the code compiles. Combine these implications: if you do not specify a version, then the version is before C++11. – JaMiT Feb 18 '23 at 03:14

0 Answers0