Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > The least used keywords in C++, which do you use?

Reply
Thread Tools

The least used keywords in C++, which do you use?

 
 
James Kanze
Guest
Posts: n/a
 
      09-19-2007
On Sep 18, 11:49 am, "Alf P. Steinbach" <(E-Mail Removed)> wrote:
> * James Kanze:
> > I'm surprised that Alf didn't mention wchar_t. If I need
> > Unicode, I'll use uint32_t, given that wchar_t isn't guaranteed
> > to suffice (and doesn't on some common platforms). Except that
> > even more often, I'll use UTF-8, which means that char is fine.


> I actually use wchar_t and have used wchar_t a lot.


> It plays about the same rôle as int, the platform's "natural" wide
> character type.


I guess part of the problem is that there is no generally
established convention as to what a "natural" wide character
type should support.

> And it has the same problems: some things are more portable with wchar_t
> (such as std::wstring for holding platform-specific wide character
> strings), and some things are less portable with wchar_t (such as code
> that assumes a specific encoding, or other size-dependent assumption).


> And the same issues seem to hold for plain char.


To some degree. The difference is that when I use char, I
expect to be dealing with different encodings. The usual reason
for going beyond char is to have a specific encoding (Unicode),
and to avoid multi-byte encodings.

In the future, of course, we'll have char32_t.

> On a platform with 16-bit char I imagine one wouldn't use
> std::string for holding a narrow character string.


Sure you would. On a platform with 16-bit char, there's no
smaller type available.

>From a practical point of view: there are three sizes of

characters: 8 bit, 16 bit and 32 bit. (8 bit also encompasses
smaller encodings, like 7 bit ASCII. But these aren't very
relevant today.) And you have to know which one you're dealing
with. char is guaranteed to be at least 8 bit, so it's fine for
that. (Not completely, since char can be signed, which
introduces some problems. But it's usable.) wchar_t is also
guaranteed to be at least 8 bits, which is useless. In
practice, wchar_t can probably be counted on to be at least 16
bits on most general purpose platforms, so it can probably be
used for the 16 bit characters, but the 16 bit ones are the ones
I use the least. But what about the 32 bit ones? I currently
use uint32_t.

--
James Kanze (GABI Software) email:(E-Mail Removed)
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

 
Reply With Quote
 
 
 
 
James Kanze
Guest
Posts: n/a
 
      09-19-2007
On Sep 18, 2:03 pm, mathieu <(E-Mail Removed)> wrote:
> On Sep 18, 12:27 pm, Juha Nieminen <(E-Mail Removed)> wrote:


> > Alf P. Steinbach wrote:
> > > Here's the list of keywords and reserved words (the difference in C++
> > > escapes me!) that I don't use:


> > > export, auto, register, and, and_eq, or, or_eq, xor, xor_eq, not,
> > > not_eq, bitand, bitor, compl


> > How about 'signed'?


> How about virtual for class inheritance


I don't think I've ever written an application without some
virtual inheritance. (Not that that's relevant to Alf's
question; he asked about keywords, not features. And the
keyword virtual certainly serves.)

--
James Kanze (GABI Software) email:(E-Mail Removed)
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

 
Reply With Quote
 
 
 
 
Zara
Guest
Posts: n/a
 
      09-19-2007
On Tue, 18 Sep 2007 02:14:42 -0700, James Kanze
<(E-Mail Removed)> wrote:

>On Sep 17, 8:34 pm, "Bo Persson" <(E-Mail Removed)> wrote:
>> Daniel T. wrote:

>
>> :: "Alf P. Steinbach" <(E-Mail Removed)> wrote:

>
>> ::: Here's the list of keywords and reserved words (the difference in
>> ::: C++ escapes me!) that I don't use:

>
>> ::: export, auto, register, and, and_eq, or, or_eq, xor, xor_eq,
>> ::: not, not_eq, bitand, bitor, compl

>
>> ::: How about you?

>
>> :: I have been programming in C/C++ for going on 10 years and I have
>> :: never used 'continue', I only use 'break' inside a switch
>> :: statement. Lastly, I have never used 'goto'.

>
>> Also asm is about as useful as goto.

>
>It depends on what level you're programming on. I tend to
>prefer separate modules, written in assembler, to asm, but I do
>use assembler for certain very low level threading primitives
>(atomic increment, etc.), on some machines.
>
>> I don't find much practical use
>> for signed either (signed char, anyone?).

>
>> Might have used typeid and volatile about once each. .-)

>
>I don't use volatile today, but I worked on embedded systems in
>the past, and it found use there.


In embedded design, volatile is used when definig an struc serving as
interface to hardware. I use it a lot.

> And typeid pops up a lot in
>experiments and demo programs (although it is practically unused
>in applications).


Lucky you! When you use a not-enough-standar-complying compiler (let´s
say, CodeGear/Borland) and you want to use boost/variant, you are
forced to use typeid from time to time. But I agree, it is not a
required use for most compilers

Best regards,

zara
 
Reply With Quote
 
Alf P. Steinbach
Guest
Posts: n/a
 
      09-19-2007
* James Kanze:
> On Sep 18, 11:49 am, "Alf P. Steinbach" <(E-Mail Removed)> wrote:
>
>> On a platform with 16-bit char I imagine one wouldn't use
>> std::string for holding a narrow character string.

>
> Sure you would. On a platform with 16-bit char, there's no
> smaller type available.


Oh there is. There's always the bit. As I wrote I have no experience
with such platforms, but if memory was tight I would at least consider
doing things like

typedef unsigned char UChar;

class DoubleChar
{
STATIC_ASSERT( CHAR_BITS >= 16 );
private:
UChar myValues;
public:
static char firstOf( char c ) { return c && 0xFF; }
static char secondOf( char c ) { return (c >> & 0xFF; }

DoubleChar( char v1, char v2 )
: myValues( UChar(v1) | (UChar(v2) << )

char operator[]( ptrdiff_t i ) const
{ return (i == 0? firstOf( myValues ) : secondOf( myValues ); }

char value() const { return myValues; }
};

and then store these double-chars packed in an array with

char operator[]( ptrdiff_t i ) const
{ return myDoubleValues[i/2][i%2]; }


> From a practical point of view: there are three sizes of
> characters: 8 bit, 16 bit and 32 bit. (8 bit also encompasses
> smaller encodings, like 7 bit ASCII. But these aren't very
> relevant today.) And you have to know which one you're dealing
> with. char is guaranteed to be at least 8 bit, so it's fine for
> that. (Not completely, since char can be signed, which
> introduces some problems. But it's usable.) wchar_t is also
> guaranteed to be at least 8 bits, which is useless. In
> practice, wchar_t can probably be counted on to be at least 16
> bits on most general purpose platforms, so it can probably be
> used for the 16 bit characters, but the 16 bit ones are the ones
> I use the least. But what about the 32 bit ones? I currently
> use uint32_t.


OK, I think that's a very clear exposition.

Do you have any type advice for my hobby string project (now on ice for
a week or so), at <url: http://alfsstringvalue.sourceforge.net/>?

I think I'd like to get things type-wise Right(TM) before putting out a
release...

Cheers,

- Alf

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
 
Reply With Quote
 
James Kanze
Guest
Posts: n/a
 
      09-20-2007
On Sep 19, 12:10 pm, "Alf P. Steinbach" <(E-Mail Removed)> wrote:
> * James Kanze:
> > On Sep 18, 11:49 am, "Alf P. Steinbach" <(E-Mail Removed)> wrote:


> > From a practical point of view: there are three sizes of
> > characters: 8 bit, 16 bit and 32 bit. (8 bit also encompasses
> > smaller encodings, like 7 bit ASCII. But these aren't very
> > relevant today.) And you have to know which one you're dealing
> > with. char is guaranteed to be at least 8 bit, so it's fine for
> > that. (Not completely, since char can be signed, which
> > introduces some problems. But it's usable.) wchar_t is also
> > guaranteed to be at least 8 bits, which is useless. In
> > practice, wchar_t can probably be counted on to be at least 16
> > bits on most general purpose platforms, so it can probably be
> > used for the 16 bit characters, but the 16 bit ones are the ones
> > I use the least. But what about the 32 bit ones? I currently
> > use uint32_t.


> OK, I think that's a very clear exposition.


For what I do. (In production code, I almost always use
UTF-8 for Unicode, so it's char all the way.)

> Do you have any type advice for my hobby string project (now on ice for
> a week or so), at <url:http://alfsstringvalue.sourceforge.net/>?


Only to make it a template, and let the user choose. There's no
one right solution.

--
James Kanze (GABI Software) email:(E-Mail Removed)
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

 
Reply With Quote
 
Mirek Fidler
Guest
Posts: n/a
 
      09-21-2007
On Sep 17, 6:01 pm, "Victor Bazarov" <(E-Mail Removed)> wrote:
> Alf P. Steinbach wrote:
> > Here's the list of keywords and reserved words (the difference in C++
> > escapes me!) that I don't use:

>
> > export, auto, register, and, and_eq, or, or_eq, xor, xor_eq, not,
> > not_eq, bitand, bitor, compl

>
> > How about you?


> I don't recall the last time I used 'goto'.


I have no problem using 'goto' and I use it from time to time (quick
scan of my codebase reveals one goto per 5000 lines...).

'delete' is on my list of rarely used reserved words rigth after the
goto. I use it only when interfacing with libs.

Mirek

 
Reply With Quote
 
Sarath
Guest
Posts: n/a
 
      09-21-2007
On Sep 21, 7:38 pm, Mirek Fidler <(E-Mail Removed)> wrote:
> On Sep 17, 6:01 pm, "Victor Bazarov" <(E-Mail Removed)> wrote:
>
> > Alf P. Steinbach wrote:
> > > Here's the list of keywords and reserved words (the difference in C++
> > > escapes me!) that I don't use:

>
> > > export, auto, register, and, and_eq, or, or_eq, xor, xor_eq, not,
> > > not_eq, bitand, bitor, compl

>
> > > How about you?

> > I don't recall the last time I used 'goto'.

>
> I have no problem using 'goto' and I use it from time to time (quick
> scan of my codebase reveals one goto per 5000 lines...).
>
> 'delete' is on my list of rarely used reserved words rigth after the
> goto. I use it only when interfacing with libs.
>
> Mirek


May be the least or never used keyword is goto

In a way using switch case is also something like goto

Regards,
Sarath

 
Reply With Quote
 
Earl Purple
Guest
Posts: n/a
 
      09-21-2007
On 18 Sep, 10:09, James Kanze <(E-Mail Removed)> wrote:
> Unless you're doing very low level programming, reinterpret_cast probably remains unused as
> well.


Or using a C interface that normally involves a strange cast, eg dlsym
which returns void * as a pointer to anything, even a function, or
"pointer to pointer" which is seen as a different level of indirection
by static_cast even though it really is a pointer to something.

> And of course, I've never used continue or goto, in over 25
> years of C/C++. And when I encounter it in code I have to work
> on, I simply throw the code out and start over.


I have never used goto but continue isn't really evil, any more than
break is. Yes you can put in a block to the end of the loop that is
not called but continue is simpler. I would say that not using
continue is a style issue only. I also sometimes return from the
middle of functions. Maybe you consider that evil too.

Having said that I couldn't find an instance of "continue" used in my
own code.

> > I don't use the operators ('and', 'or', etc.) mostly because
> > those are less readable than symbols ('&&', '||'), and
> > readability is one of the cornerstones of maintainability of
> > the code when a larger team is concerned.


There is no logical xor as far as I'm aware, so why isn't the function
called bit_xor which shows which group it belongs in.

In logical terms, logical_xor( 1, 2 ) = false (they are both non-zero)
while logical_and( 1, 2 ) = true (same reason). In bitwise terms
bitwise_xor( 1, 2 ) = 3 while bitwise_and( 1, 2 ) = 0

If without the prefixes, and and or mean the logical variety then xor
should mean the same.



 
Reply With Quote
 
Victor Bazarov
Guest
Posts: n/a
 
      09-21-2007
Sarath wrote:
> [..]
> In a way using switch case is also something like goto


Remember the arithmetic goto in Fortran?

Actually, switch/case is more like using a jump table (which is
probably not possible in C++, it doesn't have arrays of labels).

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask


 
Reply With Quote
 
Vladislav.Lazarenko@gmail.com
Guest
Posts: n/a
 
      09-21-2007
I never use goto and see it only in my nightmares

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need regular expression for at least 7 characters and at least 1 special chatacter AAaron123 ASP .Net 0 10-03-2008 01:25 PM
Which film characters would you least like having as a neighbor and why ? Eric DVD Video 3 09-14-2007 12:26 PM
Keywords list used in VisualStudio 2005 -reg Thirumalai ASP .Net 2 06-22-2006 08:59 AM
Re: Least used builtins? Sean 'Shaleh' Perry Python 2 07-05-2003 03:57 AM



Advertisments