Hacker News
new
|
past
|
comments
|
ask
|
show
|
jobs
|
submit
login
cassepipe
on April 6, 2023
|
parent
|
context
|
favorite
| on:
C Strings and my slow descent to madness
I don't have MacOs to prove it but I believe `strcmp` on MacOs returns either 0, 1 or -1
saagarjha
on April 7, 2023
|
next
[–]
It currently returns a character difference. Don’t rely on it, though!
skywal_l
on April 6, 2023
|
prev
[–]
https://developer.apple.com/library/archive/documentation/Sy...
cpeterso
on April 6, 2023
|
parent
[–]
strcmp's return value is loosely defined because some implementations return the difference between the characters in the string to avoid some conditional checks or jumps. Something like:
int d = a[i] - b[i]; if (d == 0) return d;
Guidelines
|
FAQ
|
Lists
|
API
|
Security
|
Legal
|
Apply to YC
|
Contact
Search: