Hacker News
new
|
past
|
comments
|
ask
|
show
|
jobs
|
submit
login
timbre
on June 19, 2012
|
parent
|
context
|
favorite
| on:
The Little C Function From Hell
I'm rusty on C, and confused. What should I use instead of signed int?
rcfox
on June 19, 2012
[–]
unsigned int :)
bvdbijl
on June 19, 2012
|
parent
[–]
and for negative numbers?
rcfox
on June 19, 2012
|
root
|
parent
[–]
In that case, you can be pretty certain that you need a signed integer.
esrauch
on June 20, 2012
|
root
|
parent
[–]
What if you
only
need to store negative integers?
duaneb
on June 20, 2012
|
root
|
parent
[–]
Isn't that the same situation as only storing signed integers? The arithmetic is just a little different.
ralph
on June 20, 2012
|
root
|
parent
[–]
No, you get room for one more negative int. x = x < 0 ? -x : x; is a common buggy abs(), e.g. when printing an integer. One should test if it's negative, perhaps print the '-', and then ensure it's negative for the rest of the per-digit code.
Join us for
AI Startup School
this June 16-17 in San Francisco!
Guidelines
|
FAQ
|
Lists
|
API
|
Security
|
Legal
|
Apply to YC
|
Contact
Search: