Thread: Please rate at my code

  1. #16
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Quote Originally Posted by Sebastiani View Post
    Either way, ASSERTS ARE STRICTLY FOR DEBUGGING and should ALWAYS be disabled in the release build, regardless of the size or complexity of the program...
    Not entirely...
    There is such a thing as compile-time asserts. In C++ that typically means static_assert, or in C various macros like C_ASSERT are used. These are used precisely for finding mistakes at compile time, without having to debug the program. That is what should be used in this case.
    Also, compile-time asserts are meant to be enabled for all project build types, which is fine since they have no run-time impact.


    Make sure you test your function for an input value of -2147483648. An implementation that does not use an unsigned type internally will normally fail with that value, asuming 32-bit ints.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  2. #17
    Registered User
    Join Date
    May 2012
    Posts
    505
    Quote Originally Posted by Barney McGrew View Post
    Mostly, I'd think. I suppose there are also situations where you might want to print an integer with padding in a base that isn't supported by the *printf family.
    Quite often you don't have a sprintf(). On an embedded system it might not be provided. On MS Windows you have wsprintf(), but it doesn't handle floating point values (no kidding), so you have to implement your own. Whilst my_atoi couldn't be used as it stands, it would be simple to retype char as w_char.
    I'm the author of MiniBasic: How to write a script interpreter and Basic Algorithms
    Visit my website for lots of associated C programming resources.
    https://github.com/MalcolmMcLean


Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Rate this code? what could i have done better?
    By SuperMiguel in forum C Programming
    Replies: 23
    Last Post: 07-08-2012, 05:51 PM
  2. Rate my code
    By Baard in forum C++ Programming
    Replies: 2
    Last Post: 01-04-2004, 09:19 AM
  3. rate my directx code
    By revelation437 in forum Game Programming
    Replies: 9
    Last Post: 01-02-2004, 06:21 PM
  4. Rate my source code :)
    By Terrance in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 10-17-2003, 01:09 PM
  5. rate my code
    By kashifk in forum C Programming
    Replies: 1
    Last Post: 06-07-2003, 12:18 PM