Re: Are _T() and TEXT() macros equivalent?



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. Newcomer
<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!
Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.



Relevant Pages

  • Re: asm and C/C++ data types
    ... should've stated better was "a char in C is the minimum" changed to "a char ... approaches that have been taken by C implementations. ... separate bit of storage is attached to char and void pointers to hold ... to other pointer types or used for addressing without shifting things ...
    (alt.lang.asm)
  • Re: asm and C/C++ data types
    ... A "char" in C is a C byte. ... approaches that have been taken by C implementations. ... separate bit of storage is attached to char and void pointers to hold ... to other pointer types or used for addressing without shifting things ...
    (alt.lang.asm)
  • Re: asm and C/C++ data types
    ... A "char" in C is a C byte. ... That's also one of the reasons the internals of pointers are so ... approaches that have been taken by C implementations. ... to other pointer types or used for addressing without shifting things ...
    (alt.lang.asm)
  • Re: [PATCH] Create PNP device attributes via dev_attrs field of struct device
    ... The patch below is my first attempt at addressing this by creating ... *protocol, int id, char *pnpid ... int ret; ... struct device_attribute *attr, char *buf) ...
    (Linux-Kernel)
  • Re: Are _T() and TEXT() macros equivalent?
    ... critically depend on char being one addressible unit, ... indeed, char is the fundamental unit of addressing in C and C++, ... For example, the registry API ... etc. (It was a TI TMS30Cxx chip, ...
    (microsoft.public.vc.mfc)

Loading