Re: Are _T() and TEXT() macros equivalent?
- From: Joseph M. Newcomer <newcomer@xxxxxxxxxxxx>
- Date: Wed, 11 Apr 2007 17:07:44 -0400
Yes, I was agreeing with you that a change that made size(char) == 2 would be a disaster.
joe
On Mon, 09 Apr 2007 20:38:34 -0500, "Doug Harrison [MVP]" <dsh@xxxxxxxx> wrote:
On Mon, 09 Apr 2007 20:03:53 -0400, Joseph M. NewcomerJoseph M. Newcomer [MVP]
<newcomer@xxxxxxxxxxxx> wrote:
On Mon, 09 Apr 2007 10:53:22 -0500, "Doug Harrison [MVP]" <dsh@xxxxxxxx> wrote:
On Mon, 09 Apr 2007 02:44:27 -0400, Joseph M. Newcomer
<newcomer@xxxxxxxxxxxx> wrote:
Well, the advantage of a standard is that the code works as written in all contexts. If
'char' suddenly became 16 bits, most programs would stop working, because they really
critically depend on char being one addressible unit, not 2 addressible units.
That's not quite right. Truly portable programs can deal with 8 bit chars,
16 bit chars, etc, all of which are permissible. By definition,
sizeof(char) == 1, so char can never, ever have more than one addressable
unit; indeed, char is the fundamental unit of addressing in C and C++,
irrespective of what the hardware may support. However, programs frequently
assume 8 bit chars, and a 16 bit char could indeed throw them for a loop.
(Fact: To add to the confusion, the C and C++ Standards use the terms
"char" and "byte" interchangeably; they are exact synonyms, and in that
context, "byte" doesn't imply "octet".)
That was my point; if you define 'char' to be Unicode, it violates sizeof(char) premises
that are wired deeply into a lot of programs. The resulting chaos of changing 'char' such
that sizeof(char) == 2 would be disastrous.
I meant what I said literally:
By definition,
sizeof(char) == 1, so char can never, ever have more than one addressable
unit; indeed, char is the fundamental unit of addressing in C and C++,
irrespective of what the hardware may support.
That is, the language defines sizeof(char) == 1. Always. For this reason,
it does not make sense to talk about sizeof(char) == 2 or char having more
than one addressable unit. You can't address anything smaller than char in
C or C++, regardless of how many bits char has, and sizeof(char) == 1 by
definition.
Think of all the places where in doing
Unicode we have to *sizeof(TCHAR) or /sizeof(TCHAR).
If char were widened from 8 to 16 bits, that would pose a problem only for
code or APIs that assumed 8 bit chars. For example, the registry API
requires you to specify buffer sizes in "bytes," and by that they mean the
usual interpretation as 8-bit quantities. But if the registry API (and
everything else, including disk files, data on the wire, etc) widened in
the same way, it would be fine. Then the system would be using "bytes" that
are the same size as the C++ "char", which is the situation we're all used
to.
A friend once built a compiler where sizeof(char) = sizeof(short) = sizeof(int) =
sizeof(double) = sizeof(float) = 1, where char was 80 bits wide, as was short, as was int,
etc. (It was a TI TMS30Cxx chip, a super-high-performance DSP chip).
And that's perfectly legal!
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.
- Follow-Ups:
- Re: Are _T() and TEXT() macros equivalent?
- From: Doug Harrison [MVP]
- Re: Are _T() and TEXT() macros equivalent?
- References:
- Re: Are _T() and TEXT() macros equivalent?
- From: MrAsm
- Re: Are _T() and TEXT() macros equivalent?
- From: David Ching
- Re: Are _T() and TEXT() macros equivalent?
- From: Mihai N.
- Re: Are _T() and TEXT() macros equivalent?
- From: David Ching
- Re: Are _T() and TEXT() macros equivalent?
- From: Mihai N.
- Re: Are _T() and TEXT() macros equivalent?
- From: David Ching
- Re: Are _T() and TEXT() macros equivalent?
- From: Joseph M . Newcomer
- Re: Are _T() and TEXT() macros equivalent?
- From: Doug Harrison [MVP]
- Re: Are _T() and TEXT() macros equivalent?
- From: Joseph M . Newcomer
- Re: Are _T() and TEXT() macros equivalent?
- From: Doug Harrison [MVP]
- Re: Are _T() and TEXT() macros equivalent?
- Prev by Date: Embedded Power Point Sample
- Next by Date: Visa Journal Playback hook
- Previous by thread: Re: Are _T() and TEXT() macros equivalent?
- Next by thread: Re: Are _T() and TEXT() macros equivalent?
- Index(es):
Relevant Pages
|
Loading