Skip to content

Instantly share code, notes, and snippets.

@aji
Created May 22, 2013 23:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aji/5631713 to your computer and use it in GitHub Desktop.
Save aji/5631713 to your computer and use it in GitHub Desktop.
unsigned int numeric_atoi(const char *s)
{
return ((s[0] - '0') * 100)
+ ((s[1] - '0') * 10)
+ ((s[2] - '0'));
}
@aji
Copy link
Author

aji commented May 22, 2013

#define numeric_atoi(s) \
  ((((s)[0] - '0') * 100) + \
   (((s)[1] - '0') * 10) + \
   (((s)[2] - '0')))

@aji
Copy link
Author

aji commented May 22, 2013

If you're pretty sure multiple evaluation of s is okay.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment