Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Keith Thompson <kst-u@mib.org> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: unsigned int |
| Date | 2016-08-01 12:02 -0700 |
| Organization | None to speak of |
| Message-ID | <lnpops48jt.fsf@kst-u.example.com> (permalink) |
| References | (1 earlier) <e06rglFmcd5U1@mid.individual.net> <nnn35u$2dd$1@dont-email.me> <nnnnqr$589$1@dont-email.me> <nnnpdf$b3s$1@dont-email.me> <nno33q$fto$1@dont-email.me> |
Les Cargill <lcargill99@comcast.com> writes:
> David Brown wrote:
[...]
> So I'm calling that a swing and a miss. A char is an int that is
> constrained to be less bits.
The name "int" refers to one of several integer types. `char` is one
integer type, `int` is another.
> All chars have exactly the same semantics
> as ints.
No. All character types have the same semantics as integer types in
general. Obviously the semantics of signed and unsigned integer types
differ; plain `char` can be either. And the character types have some
semantics that the other integer types do not (aliasing, requirements
for no padding bits).
> Default char in 'C' is always unsigned unless you use compiler
> options to make it otherwise, or unless the compiler defaults it for you.
It would be equally accurate to say that `char` is always signed unless
it isn't.
Plain `char` is *either* signed *or* unsigned. There is no general
sense in which unsigned is the default and signed is not.
[...]
> The problem is that there's a great and powerful simplifying assumption
> in play - 'a' is exactly equivalent to the integer 0xa1. I find this
> quite comforting; it's a simple rule.
Where did you get the value 0xa1? 'a' is 0x61 in ASCII, 0x81 in EBCDIC.
>> I would like a type "byte" which
>> represents raw data in memory - "byte *" would be used instead of "void
>> *" in C, and also in many cases where "char *" is used.
>
> I rather like "void *" because void is the identity un-type - it is a
> type with zero semantic information about it. A void * is a pointer for
> the sake of a pointer, used only as an r-value in order to assign or
> cast to a richer type.
void* is a pointer to arbitrary data. The suggested "byte" type (or
unsigned char in current C) can *contain* arbitrary data. Big
difference.
[...]
> Because warnings. With the right compiler options, C++ expects a char *
> to be a char *, not some typedef equivalent to a char *.
>
> This happens with Mingw 3.4.5 with g++ -I . -Wall -c
Hmm? In both C and C++, "typedef" creates a new name for an existing
type. Do you have an example where g++ complains about mixing char*
with a type name that's a typedef for char*?
[...]
> #assert(CHAR_BIT==8) is easy enough.
But non-standard; there is no #assert directive (unless it's an
extension).
[...]
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: unsigned int "Osmium" <r124c4u102@comcast.net> - 2016-07-31 12:40 -0500
Re: unsigned int David Brown <david.brown@hesbynett.no> - 2016-08-01 11:01 +0200
Re: unsigned int James Kuyper <jameskuyper@verizon.net> - 2016-08-01 10:15 -0400
Re: unsigned int Les Cargill <lcargill99@comcast.com> - 2016-08-01 09:59 -0500
Re: unsigned int David Brown <david.brown@hesbynett.no> - 2016-08-01 17:21 +0200
Re: unsigned int Keith Thompson <kst-u@mib.org> - 2016-08-01 09:55 -0700
Re: unsigned int David Brown <david.brown@hesbynett.no> - 2016-08-01 22:42 +0200
Re: unsigned int supercat@casperkitty.com - 2016-08-01 14:18 -0700
Re: unsigned int Les Cargill <lcargill99@comcast.com> - 2016-08-01 13:11 -0500
Re: unsigned int Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-08-01 19:46 +0100
Re: unsigned int Les Cargill <lcargill99@comcast.com> - 2016-08-01 18:20 -0500
Re: unsigned int David Brown <david.brown@hesbynett.no> - 2016-08-02 10:18 +0200
Re: unsigned int Les Cargill <lcargill99@comcast.com> - 2016-08-02 09:35 -0500
Re: unsigned int Keith Thompson <kst-u@mib.org> - 2016-08-02 08:00 -0700
Re: unsigned int Les Cargill <lcargill99@comcast.com> - 2016-08-02 11:12 -0500
Re: unsigned int David Brown <david.brown@hesbynett.no> - 2016-08-02 17:11 +0200
Re: unsigned int Les Cargill <lcargill99@comcast.com> - 2016-08-02 11:55 -0500
Re: unsigned int supercat@casperkitty.com - 2016-08-02 10:16 -0700
Re: unsigned int David Brown <david.brown@hesbynett.no> - 2016-08-03 14:02 +0200
Re: unsigned int Keith Thompson <kst-u@mib.org> - 2016-08-03 08:58 -0700
Re: unsigned int James Kuyper <jameskuyper@verizon.net> - 2016-08-02 13:57 -0400
Re: unsigned int Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-08-02 19:30 +0100
Re: unsigned int Keith Thompson <kst-u@mib.org> - 2016-08-02 11:38 -0700
Re: unsigned int David Brown <david.brown@hesbynett.no> - 2016-08-03 14:12 +0200
Re: unsigned int David Brown <david.brown@hesbynett.no> - 2016-08-03 13:45 +0200
Re: unsigned int Keith Thompson <kst-u@mib.org> - 2016-08-01 12:02 -0700
Re: unsigned int David Brown <david.brown@hesbynett.no> - 2016-08-01 23:01 +0200
csiph-web