Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

You don't need to do wacky things with pointers to get into trouble in C:

  int i;

  /* Iterates over everything except the last n elements of array... right? */
  for (i = 0; i < length - innocent_little_function(); i++)
      do_something_with(array[i]);


>You don't need to do wacky things...

A function call in a for loop's conditional doesn't fit your definition of wacky?


A function call in a for loop's conditional is practically C best practice. K&R do it on almost every page.


They usually only do it for builtins (e.g., strlen) and const functions, which makes this example a lot safer.


A bit suspicious, maybe? I was trying to suggest the unsigned issue without actually spelling it out, not anything to do with side effects.

I probably should have used sizeof, even though that doesn't make sense there.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: