Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: When does the type of a character constant make a difference? |
| Date | 2015-10-24 17:50 +0100 |
| Organization | A noiseless patient Spider |
| Message-ID | <87h9lgmcr1.fsf@bsb.me.uk> (permalink) |
| References | <n0g6oe$so9$1@solani.org> <n0gaov$ble$1@dont-email.me> |
Bartc <bc@freeuk.com> writes: > On 24/10/2015 16:05, Philipp Klaus Krause wrote: >> Character constants are of type int, not char in the standard (ignoring >> wide character constants, which might be of other types, such as char). >> But in which situations does this make a real difference? The only one I >> can think of now is generic selections. > > I was doing a test but came across something funny (probably just > another quirk I wasn't aware of). > > Although 'A' has type int, it only apparently acquires type int after > converting from type char. No, there's no conversion (in the C language sense of the term) going on. > Because if char is signed, then a value such as '£' (which is code 156 > on my machine, a UK pound sign), has the value -100 even though '£' is > has type signed int which has enough range to represent it as 156. It's much simpler to say that '£' is the int value -100. It's not converted from anything. You could help the unwary out by explaining *why* it makes sense to give '£' the int value -100 when char is a signed type, but it confuses the issue to say that C converts anything here. <snip> -- Ben.
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
When does the type of a character constant make a difference? Philipp Klaus Krause <pkk@spth.de> - 2015-10-24 17:05 +0200
Re: When does the type of a character constant make a difference? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-10-24 16:55 +0100
Re: When does the type of a character constant make a difference? raltbos@xs4all.nl (Richard Bos) - 2015-10-24 15:59 +0000
Re: When does the type of a character constant make a difference? Bartc <bc@freeuk.com> - 2015-10-24 17:16 +0100
Re: When does the type of a character constant make a difference? Richard Damon <Richard@Damon-Family.org> - 2015-10-24 12:41 -0400
Re: When does the type of a character constant make a difference? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-10-24 17:50 +0100
Re: When does the type of a character constant make a difference? Keith Thompson <kst-u@mib.org> - 2015-10-24 13:05 -0700
Re: When does the type of a character constant make a difference? Bartc <bc@freeuk.com> - 2015-10-24 22:09 +0100
Re: When does the type of a character constant make a difference? Nobody <nobody@nowhere.invalid> - 2015-10-26 06:15 +0000
Re: When does the type of a character constant make a difference? raltbos@xs4all.nl (Richard Bos) - 2015-10-26 09:07 +0000
csiph-web