Thread: Playing around strlen :)

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Code:
    //They said passing by reference gives better performance:
    
    int strlen_byref(char **str)
    That's not passing by reference. You cannot pass by reference in C. That's passing a pointer to a pointer, by value, and it only decreases performance.

    You can't stop a crash from occurring when passing in an uninitialised pointer. Checking for NULL is the caller's responsibility, as usually the passed pointer is to a buffer and would not be NULL.

    Comments are welcome
    Questions are welcome
    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. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    >int strlen(char *str)
    The library strlen() returns a size_t versus an int, which would allow for longer strings. I like strlen_simple(), but with a char *str instead of char **str as the parameter. It requires one local variable versus the first version, but I don't see where that makes it less attractive than the first version.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. PC or Console gamers, what are you playing?
    By indigo0086 in forum A Brief History of Cprogramming.com
    Replies: 119
    Last Post: 04-14-2008, 08:17 AM
  2. How do I keep the sounds playing?
    By Queatrix in forum Windows Programming
    Replies: 0
    Last Post: 07-21-2007, 10:19 AM
  3. strlen in expressions
    By justforthis1 in forum C++ Programming
    Replies: 4
    Last Post: 10-24-2006, 10:28 AM
  4. strlen()
    By exoeight in forum C Programming
    Replies: 9
    Last Post: 04-01-2005, 10:18 AM
  5. Just say NO to strlen.
    By anonytmouse in forum A Brief History of Cprogramming.com
    Replies: 24
    Last Post: 02-11-2005, 01:34 PM

Tags for this Thread