mardi 7 septembre 2021

How do I compile with C++98 on MacOS?

I need to use C++98 for university programs, however even when passing the -std=c++98 flag to clang++ or to g++ it still seems to compile with c++11 and does not give errors if I use c++11 features. Here is a simple example:

#include <string>
#include <sstream>
using namespace std;
int main()
{
    int i;
    string number = "12";
    i = stoi(number);
}

My makefile:

all:
    clang++ -std=c++98 -c *.cpp
    clang++ -o main *.o

clean:
    rm -f *.o main

run: clean all
    ./main

Then I run the command make from Terminal (I tried using clang++ instead of g++ but it yields the same result) and receive the following output:

➜  cppversion make
g++ -std=c++98 -c *.cpp
g++ -o main *.o
➜  cppversion make
clang++ -std=c++98 -c *.cpp
clang++ -o main *.o
➜  cppversion

I believe this code should not have compiled if the -std=c++98 flag was working. How do I force code to compile with c++98?

Aucun commentaire:

Enregistrer un commentaire