Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Who needs exceptions?

Name: Anonymous 2012-07-04 20:46


//in some class or namespace:
typedef unsigned int error_code;
const error_code out_of_mem = 0x01,
  niggers = 0x02,
  jews = 0x04;

error_code f()
{
  error_code ret = 0;
  //do some stuff...
  //suddenly niggers
  ret |= niggers;
  //but it's not a fatal error so we will continue execution
  //...
  if(some_pointer == nullptr)
  {
    ret |= out_of_mem;
    goto cleanup;
  }
  //and so on...
cleanup:
  delete some_pointer;
  //etc...

  return ret;
}

void implementation()
{
  error_code f = f();
  if( f & out_of_mem )
    //handle error
    printf("%s\n", "allocation failure");

  if( f & niggers )
    pool.close();
}


The main point of exceptions is to separate error detection from error handling. This accomplishes that. If you need the advanced features of exceptions, take a good look at your design and, more importantly, your life.

Name: Cudder !MhMRSATORI!fR8duoqGZdD/iE5 2012-07-09 1:14

http://lyngvig.org/a-proposal-for-exception-handling-in-c.ashx

Using the CPU's carry flag for returning boolean values and signaling errors: It's been over 30 years since the 8086 was released, and we are finally seeing some of these established efficient customs of asm propagating to the first level of high-level languages. Nothing can beat the 1 + 2n bytes needed to return a boolean like this (1 byte to set, 2 bytes to test+jump per callsite); the best C compilers will generate a 2 + 4n (2 bytes to set, 2 bytes to test + 2 bytes to jump per callsite).

See also: custom calling conventions, return address retargeting, cross-function register allocation, etc.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List