Re: Why is there a keyword "signed" if its default?

Posted 06 September 2011 - 03:53 AM

Well, let's say you have some variable which for whatever reasons must be signed. Let's say that Joe Random Programmer shows up a few days later and looks at your code and things "herp de doo, let's make it unsigned because it's too small". What happens? Crash. Why? Because you didn't make it clear that the variable had to be signed.

Joe Random Programmer can also be you, not always some other person when working in a group.

Re: Why is there a keyword "signed" if its default?

Posted 06 September 2011 - 04:03 AM

I agree, but these systems all exist to allow people with preferred coding styles to code their own way. It's also possible you're compiling on some obscure system that might not necessarily default to signed.

Re: Why is there a keyword "signed" if its default?

Re: Why is there a keyword "signed" if its default?

Posted 06 September 2011 - 04:40 AM

As has already been pointed out, the default signed-ness [edit]of any type[/edit] is going to compiler dependent. When in doubt, specify. This is also why there are handy typedefs like uint8_t..uint64_t to help convey exactly the type wanted in a particular instance.

Re: Why is there a keyword "signed" if its default?

Posted 06 September 2011 - 07:57 AM

GWatt, on 06 September 2011 - 01:40 PM, said:

As has already been pointed out, the default signed-ness [edit]of any type[/edit] is going to compiler dependent.

This is not true. The signedness of char is indeed unspecified, but shorts, ints, longs and long longs are all defined to be signed. That's also why limits.h defines both SCHAR_MIN/SCHAR_MAX and CHAR_MIN/CHAR_MAX, but doesn't do the same for any other type.