This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Use assert()s for optimization?


Hi!

Is there a way to turn an assert() into optimization hints for gcc?
Like in

double mysqrt(double x)
{
  assert(x >= 0.0);
  return sqrt(x);
}

have some way to tell the compiler x >= 0.0 is true, even in the case
of turning the assertion into a no-op? Something like

#ifdef NDEBUG
#define assert(x) if (!(x)) __builtin_not_reached()
#endif

or similar?

Thanks,

Richard.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]