2

I have my code running in Linux. I see my program getting aborted when a NULL is passed to strchr() function. This doesn't seem to happen when running in AIX.

Can anyone tell why this difference in behavior for strchr() ?

Thanks

rauschen
  • 3,956
  • 2
  • 13
  • 13
G Sij
  • 21
  • 1
  • 3

1 Answers1

1

Because the spec for strchr() doesn't specify the "correct" behavior when passed a NULL, so different implementations are free to, uh, implement it differently for that case. (Just curious: what does the AIX version return when passed a NULL?)

Scott Hunter
  • 48,888
  • 12
  • 60
  • 101
  • 1
    In AIX when passed a NULL to strchr(), it returns a NULL and the program runs without aborting. – G Sij Jan 24 '12 at 06:11
  • 5
    More precisely, the behavior is undefined, so implementations don't even have to be consistent. Either crashing or returning NULL is conforming behavior. So is making demons fly out of your nose. – Keith Thompson Jan 24 '12 at 09:36