Topic: Char/void schizophrenia
Author: Ron Natalie <ron@spamcop.net>
Date: Wed, 6 Jun 2001 22:07:14 GMT Raw View
Ken Hagan wrote:
>
> Bjarne Stroustrup <bs@research.att.com> wrote...
> >
> > In a language supporting low-level systems programming, something
> > has to be able to refer to "raw memory", e.g. newly allocated
> > memory, the result of a read from disc, etc. Before void*, C and
> > C++ (and Unix) used char* to refer to such memory.
>
> In my experience, void is inadequate for such low-level programming,
> since you can't do arithmetic on void* pointers.
>
> One always ends up doing lots of casting to some flavour of char*.
>
Yes, and this is one point of schizophrenic meaning of char. In
one usage, it's the native character. In another, it's a generic
byte pointer (and the smallest addressable unit, and the sizeof unit).
Woe be it to any application that doesn't keep this
in mind. This is why even when char is meaningless for native
chars (because they are 16 bit), these implementations use wchar_t
as the native character and leave char as meaningless for characters
but essential for byte access.
Unfortunately, both C and C++ are equally schizophrenic in support
of wchart_t vs char. For instance, there is no requirement that
an implementation support wchar_t for main's args, for file names
and other system interfaces, for typeinfo and std::exception strings.
Then on the other hand the basic_string and fstreams have no procedure
to deal with multibyted data.
Frankly, I'd rather see these roles separated. Some type (perhaps void)
as the smallest addressable unit and the generic pointer into memory,
which sizeof is determiend with regard to, and with permitted math in
terms of that size. Then have char legitimately be the NATIVE character
type (otherwise you end up having to duplicate all the interfaces for
wchar_t).
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]