Why is even signed a reserved word? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

Why is even signed a reserved word?

Well, there are a lot of reserved words that you cannot use in more any place in the language that you are using, for example the word for, while, if, else, int, float, double..., and so on. The question is why we have a reserved word in c called signed, if for example you can write signed int number but you can write just int number without signed. So is this reserved word even useful in c language? I didn't see any type of utilities.

2nd May 2019, 5:36 PM
Werg Serium
Werg Serium - avatar
15 Answers
+ 13
nom nom nom... 🍿 gulp gulp gulp... 🥤 Don't mind me... I'm just enjoying the show. 🤓👌
2nd May 2019, 7:53 PM
David Carroll
David Carroll - avatar
+ 7
~ swim ~ But the C standard specifically specifies that there are 3 types. char, signed char and unsigned char. Again, that link I send is from the C standard, not the C++ standard. It is up to the implementation to define char to have the same meaning as a signed char or an unsigned char. But they are still distinct types. std::numeric_limits<char>::is_integer is pretty much a synonym of std::is_integral<char>::value. Again, an integral is not synonymous to the type int.
2nd May 2019, 8:16 PM
Dennis
Dennis - avatar
+ 6
The only situation I know about is with char. char, signed char and unsigned char are three distinct types according to the standard. http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf 6.2.5.15 "The three types char, signed char, and unsigned char are collectively called the character types. The implementation shall define char to have the same range, representation, and behavior as either signed char or unsigned char." So basically char is implementation defined whether it is signed or unsigned.
2nd May 2019, 6:22 PM
Dennis
Dennis - avatar
+ 6
~ swim ~ No it's not? ' ' is an int yes, but char is not an int char c = ' '; printf( "%d\n", sizeof(' ')); // 4 printf( "%d\n", sizeof(c)); // 1 Besides, that is standard C documentation, not C++.
2nd May 2019, 6:33 PM
Dennis
Dennis - avatar
+ 6
~ swim ~ Yes, I know that they are different, a char constant is an actual char in C++ and an integer in C. What I don't get it is why you suddenly went off about 'char is of type int in C' because I never suggested otherwise?
2nd May 2019, 7:27 PM
Dennis
Dennis - avatar
+ 6
~ swim ~ But I wasn't talking about char constants. I was talking about the actual char type. char, signed char and unsigned char are distinct types in both C and C++ and they are all integral types in both C and C++. std::is_integral<char>::value // 1 std::is_same<char, signed char>::value // 0 std::is_same<char, unsigned char>::value // 0
2nd May 2019, 7:47 PM
Dennis
Dennis - avatar
+ 6
So it sounds like it's all due to historical reasons.
3rd May 2019, 2:30 AM
Sonic
Sonic - avatar
+ 5
~ swim ~ char is an integral type, not an int. There is a difference. Besides, whether char is an integral or not is not the point here. I'm simply quoting the standard, you can't fight the standard. :) https://www.cs.auckland.ac.nz/references/unix/digital/AQTLTBTE/DOCU_032.HTM
2nd May 2019, 6:45 PM
Dennis
Dennis - avatar
+ 4
Werg Serium Yea, the thread went a bit off the rails over a minor thing. Sorry about that. My actual answer to you was the one with the link to open-std.org. As far as I know the 'signed' keyword only makes a difference with the char type. Because char is not defined by the standard to be signed. The standard allows implementations to decide to make it signed or unsigned as an additional type. This rule only applies to the char type ( as far as I know ). Don't go confuse it with other types, it doesn't apply to those. In practice you'll rarely, if ever, use the signed keyword, even for chars.
2nd May 2019, 10:41 PM
Dennis
Dennis - avatar
+ 3
I know this confusion about int and char. You can make arithmetic operations between char and int. You also can print an number with char, you can do many thing between int and char but one thing is right, char is not int, but you can use char as an integer of 1 byte and make operations with a "normal" int. But this does not explain the question i made.
2nd May 2019, 10:27 PM
Werg Serium
Werg Serium - avatar
+ 3
Maybe the answer it's about the 3 types of char, but even that does not make things obvious. So is the signed only useful in defining the char type?
2nd May 2019, 10:31 PM
Werg Serium
Werg Serium - avatar
+ 2
I know this confusion about int and char. You can make arithmetic operations between char and int. You also can print an number with char, you can do many things between int and char but one thing is right, char is not int, but you can use char as an integer of 1 byte and make operations with a "normal" int. But this does not explain the question i made.
2nd May 2019, 10:28 PM
Werg Serium
Werg Serium - avatar
+ 2
Well you can do it without signed for integers
2nd May 2019, 10:36 PM
Werg Serium
Werg Serium - avatar
+ 2
It's just make int a=-1 for example and if you print it will shows -1. So where the signed made difference?
2nd May 2019, 10:37 PM
Werg Serium
Werg Serium - avatar
+ 2
So signed isn't redundant as sometimes you need to define a signed or unsigned char. But is int redundent!? You can define: signed int a; unsigned int b; long int c; short int d; Or skip to: signed a; unsigned b; long c; short d; So int is not needed, but it is probably the most used type?😱
3rd May 2019, 9:36 AM
Jared Bird
Jared Bird - avatar