Hacker News new | past | comments | ask | show | jobs | submit login

If you make one small change to this file you can cause clang and gcc to both prevent this from compiling if you are using warnings.

  namespace {
    void NeverCalled() { Do = EraseAll; }
  }
or marking NeverCalled as static itself.

Results in warning: unused function NeverCalled.

In general this is best practice for functions defined and used in a single translation unit.




That's a vital part of the setup.

You could hypothetically link this compilation unit against another unit which included:

  void NeverCalled();
  struct A {
    A() { NeverCalled(); }
  };
  A a;


You don't even need C++, you can just use C and __attribute__((constructor)).


Which is a GCC specific extension and not ANSI C.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: