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

2
  • 1
    which programming language you use? This function exists in serveral languages .. – rauschen Jan 23 '12 at 13:21
  • The programming language I am using is C++ – G Sij Jan 24 '12 at 5:46
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?)

2
  • 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 6:11
  • 4
    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 9:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.