14 Replies - 1356 Views - Last Post: 06 September 2011 - 07:57 AM Rate Topic: -----

#1 hulla  Icon User is offline

  • Writing Lines


Reputation: 49
  • View blog
  • Posts: 732
  • Joined: 05-March 11

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

Posted 06 September 2011 - 03:26 AM

Why is there a keyword signed if the creation of a built-in numeric data-type is automatically signed?
Is This A Good Question/Topic? 0
  • +

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

#2 darek9576  Icon User is offline

  • D.I.C Lover

Reputation: 198
  • View blog
  • Posts: 1,691
  • Joined: 13-March 10

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

Posted 06 September 2011 - 03:33 AM

Why is there keyword private if by default class members are private?

This post has been edited by darek9576: 06 September 2011 - 03:33 AM

Was This Post Helpful? 0
  • +
  • -

#3 PlasticineGuy  Icon User is offline

  • mov dword[esp+eax],0
  • member icon

Reputation: 281
  • View blog
  • Posts: 1,436
  • Joined: 03-January 10

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

Posted 06 September 2011 - 03:35 AM

What Darek means by this is it exists to make it clearer if some data-type specifically needs to be signed or not.
Was This Post Helpful? 2
  • +
  • -

#4 hulla  Icon User is offline

  • Writing Lines


Reputation: 49
  • View blog
  • Posts: 732
  • Joined: 05-March 11

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

Posted 06 September 2011 - 03:42 AM

private is there because it is easier to read your code but signed . . . Doesn't make much sense to me but ok.

This post has been edited by hulla: 06 September 2011 - 03:43 AM

Was This Post Helpful? 0
  • +
  • -

#5 PlasticineGuy  Icon User is offline

  • mov dword[esp+eax],0
  • member icon

Reputation: 281
  • View blog
  • Posts: 1,436
  • Joined: 03-January 10

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.
Was This Post Helpful? 0
  • +
  • -

#6 hulla  Icon User is offline

  • Writing Lines


Reputation: 49
  • View blog
  • Posts: 732
  • Joined: 05-March 11

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

Posted 06 September 2011 - 04:01 AM

I would personally leave a comment or tell Joe Random to leave the keyboard in peace :) but it does make sense so thanks.
Was This Post Helpful? 0
  • +
  • -

#7 PlasticineGuy  Icon User is offline

  • mov dword[esp+eax],0
  • member icon

Reputation: 281
  • View blog
  • Posts: 1,436
  • Joined: 03-January 10

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.
Was This Post Helpful? 2
  • +
  • -

#8 hulla  Icon User is offline

  • Writing Lines


Reputation: 49
  • View blog
  • Posts: 732
  • Joined: 05-March 11

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

Posted 06 September 2011 - 04:05 AM

Oh yeah the compiler might act up with it. True.
Was This Post Helpful? 0
  • +
  • -

#9 MathiasVP  Icon User is offline

  • D.I.C Head

Reputation: 27
  • View blog
  • Posts: 154
  • Joined: 08-August 10

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

Posted 06 September 2011 - 04:24 AM

signed can be used with char to define a signed char that ranges from -127 to 127.
Was This Post Helpful? 0
  • +
  • -

#10 PlasticineGuy  Icon User is offline

  • mov dword[esp+eax],0
  • member icon

Reputation: 281
  • View blog
  • Posts: 1,436
  • Joined: 03-January 10

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

Posted 06 September 2011 - 04:31 AM

char also defaults to signed.
Was This Post Helpful? 0
  • +
  • -

#11 GWatt  Icon User is online

  • member icon

Reputation: 276
  • View blog
  • Posts: 3,075
  • Joined: 01-December 05

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.

This post has been edited by GWatt: 06 September 2011 - 04:41 AM

Was This Post Helpful? 1
  • +
  • -

#12 hulla  Icon User is offline

  • Writing Lines


Reputation: 49
  • View blog
  • Posts: 732
  • Joined: 05-March 11

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

Posted 06 September 2011 - 04:46 AM

Why is there a _t on the end?
Was This Post Helpful? 0
  • +
  • -

#13 RudiVisser  Icon User is offline

  • .. does not guess solutions
  • member icon

Reputation: 1004
  • View blog
  • Posts: 3,562
  • Joined: 05-June 09

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

Posted 06 September 2011 - 05:02 AM

View Posthulla, on 06 September 2011 - 12:46 PM, said:

Why is there a _t on the end?

_t is just a suffix for type, in the same way that MS use u as a prefix for unicode.

This is just naming conventions.
Was This Post Helpful? 0
  • +
  • -

#14 Salem_c  Icon User is offline

  • void main'ers are DOOMED
  • member icon

Reputation: 1689
  • View blog
  • Posts: 3,209
  • Joined: 30-May 10

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

Posted 06 September 2011 - 06:52 AM

View PostPlasticineGuy, on 06 September 2011 - 11:31 AM, said:

char also defaults to signed.

No it doesn't.
An unqualified char may be signed or unsigned (depending on the implementation).
Which is why gcc has -funsigned-char as an option.
Was This Post Helpful? 2
  • +
  • -

#15 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2118
  • View blog
  • Posts: 3,244
  • Joined: 21-June 11

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

Posted 06 September 2011 - 07:57 AM

View PostGWatt, 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.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1