On 12.03.2015 22:24, Paavo Helde wrote:
Which errors do you have in mind that C doesn't catch at compile
time but C++ does?
Are you kidding?
LOL, no but with your examples I'm sure YOU are kidding:
int n = 100;
long* p = malloc(n);
p[n-1] = 42;
std::vector<int> x;
x.push_back(123);
std::cerr << x[-1] << std::endl;
Totally caught at compile time *cough* NOT
enum a { a1, a2 };
enum b { b1, b2 };
void g(enum b arg) {}
g(a1);
Yup, that one is legit. It was also the example I explicitly gave.
// a.h
void foo(int x);
// a.c
// not including a.h
void foo(long x) {}
// main.c
#include "a.h"
foo(42);
ok, the latter is a linker error in C++, not compile time, but
still much better than a random error on random architecture
Oh, that is indeed neat! Nice.
return type would not be caught by linker... c++ mangles function