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

A

Alf P. Steinbach

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?
 
V

Victor Bazarov

Alf said:
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?

'auto' may get a new (extended) meaning soon. I may start using it.

'register' is definitely one we could simply get rid of. I never use it.

'export'? It's a kind of "if it were there, I might use it" keyword.
Most modern (widely available) compilers have either no, or very
rudimentary, support for it. I bet you some library implementors would
actually use it had it been better supported by the compilers.

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.

I don't recall the last time I used 'goto'. Nor can I recall needing
'friend' lately.

Because of the nature of the algorithms I'm involved with, 'short' and
'float' are not in my vocabulary either.

V
 
A

Alf P. Steinbach

* Victor Bazarov:
Because of the nature of the algorithms I'm involved with, 'short' and
'float' are not in my vocabulary either.

Thanks, I forgot those! :)

Cheers,

- Alf
 
D

Daniel T.

Alf P. Steinbach said:
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'.
 
D

duane hebert

Victor Bazarov said:
'auto' may get a new (extended) meaning soon. I may start using it.

'register' is definitely one we could simply get rid of. I never use it.
I don't recall the last time I used 'goto'. Nor can I recall needing
'friend' lately.

I haven't used register in C++ but I probably have some old C
stuff around still using it. Our "coding standard" doesn't allow
goto (for historical reasons - don't ask.) I have friend in a couple
of modules but a pending refactor will probably change that.

Because of the nature of the algorithms I'm involved with, 'short' and
'float' are not in my vocabulary either.

I do a lot of I/O stuff so short is still around but not float. The rest,
I don't use.
 
P

Puppet_Sock

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 use any of those. There are quite a few that
I don't usually bother with, or don't use often.

volatile is also one that I've had little cause to
use. I would *not* want to see it removed from the
lang. I just don't happen to write stuff where
volatile would apply.

I think there's probbaly a lot of portions of the lang
that specific people rarely, or never, use. But the
lang is a multi-paradigm language. You don't need all
the bits-and-bobs. Until the day you *do* need one of
them, and then it's there. One day I will write a code
that gets used on a real-time-hardware system that does
change the value of variables, and volatile will be
pretty important. Or, one day, I will be using a non-
English keyboard or something, and the & key won't
be they & character.
Socks
 
B

Bo Persson

Daniel T. 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. I don't find much practical use
for signed either (signed char, anyone?).

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


Perhaps we could create a new, smaller language?


Bo Persson
 
R

red floyd

Bo said:
Daniel T. 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. I don't find much practical use
for signed either (signed char, anyone?).

Might have used typeid and volatile about once each. .-)
Us bit-twiddlers use volatile a lot for registers.

We even use const volatile for read-only registers.
 
V

Victor Bazarov

Bo said:
Also asm is about as useful as goto.

I'd argue with that, but not today.
I don't find much practical use
for signed either (signed char, anyone?).

It seems that on all platforms I've been in, char was signed by default;
although, of course, char and signed char are different types... But
you're right, the keyword 'signed' is something I probably have never
used, except in an explicit template instantiation for 'signed char'.
Might have used typeid and volatile about once each. .-)

'volatile' for me was always the solution to work around some weird
optimizer bugs when the code forgets to update the memory location
of the variable. I think I've only encountered it in Visual C++,
however.
Perhaps we could create a new, smaller language?

:) Wasn't there already C-- for that?

V
 
P

Puppet_Sock

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

The last time I used 'goto' was about 1992 or so. The client
changed the spec long after I had started the coding stage.
Indeed, I was in the last throws of testing.

And suddenly, there's a new requirement that was not easy
to accomodate. Sigh.

I did learn to make some changes to my coding style such
that "that sort" of change was easier to accomodate.
But at the time, I would have either had to have rewritten
substantial code and missed the deadline, or insert one
'goto' statement. And make the deadline.

I agree that 'goto' is not something to reach for
in the usual case, or even the mildly unusual case.
Once in 15 years, and counting. But I'd be unhappy to
have it removed from the language.

I also put that section of code on my "if you change
this code for other reasons, think about cleaning
up this while you are there" list. And, no surprise,
the client changed the spec again requiring that
section to be fairly extensively rewritten. And I
got rid of the 'goto' then.
Socks
 
G

Gianni Mariani

Victor said:
'auto' may get a new (extended) meaning soon. I may start using it.

The only time I use it is to show how to use it.
'register' is definitely one we could simply get rid of. I never use it.

If an object is a "register", then you can't take the address of it
which means that the compiler is allowed to assume that it is not
aliased which (in theory) would allow for certain optimizations that it
would otherwise not.
 
P

Pete Becker

If an object is a "register", then you can't take the address of it
which means that the compiler is allowed to assume that it is not
aliased which (in theory) would allow for certain optimizations that it
would otherwise not.

That's true in C, but it's different in C++. [dcl.stc]/2-3:

The register specifier shall be applied only to names of objects declared in a
block (6.3) or to function parameters (8.4). It specifies that the
named object
has automatic storage duration (3.7.2). An object declared without a
storage-class-specifier at block scope or declared as a function parameter has
automatic storage duration by default.

A register specifier is a hint to the implementation that the object
so declared will
be heavily used. [ Note: the hint can be ignored and in most
implementations it
will be ignored if the address of the object is taken. — end note ]
 
J

James Kanze

It obviously depends on the application domain. Where I worked
before, I didn't use float or double. I've never used wchar_t
either, in an actual application. Unless you're doing very low
level programming, reinterpret_cast probably remains unused as
well.

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.
'auto' may get a new (extended) meaning soon. I may start
using it.
'register' is definitely one we could simply get rid of. I
never use it.
'export'? It's a kind of "if it were there, I might use it" keyword.

I would definitly use it. It would solve no end of problems.
Most modern (widely available) compilers have either no, or
very rudimentary, support for it. I bet you some library
implementors would actually use it had it been better
supported by the compilers.
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.

In this case, readability is in the eyes of the beholder. I'm
more used to && and || as well, but other people I know find and
and or more explicit.
I don't recall the last time I used 'goto'. Nor can I recall needing
'friend' lately.
Because of the nature of the algorithms I'm involved with,
'short' and 'float' are not in my vocabulary either.

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 also notice that "asm" is in the official list of keywords. I
certainly wouldn't recommend it in portable code, however:).
 
J

James Kanze

Daniel T. wrote:
:: "Alf P. Steinbach" <[email protected]> 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. And typeid pops up a lot in
experiments and demo programs (although it is practically unused
in applications).
 
A

Alf P. Steinbach

* 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.

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.

On a platform with 16-bit char I imagine one wouldn't use std::string
for holding a narrow character string. However, I haven't coded for
such a platform.

Cheers,

- Alf
 
J

Juha Nieminen

Alf said:
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'?
 
G

GameboyHippo

I haven't used goto in decades.

goto first_half_of_sent;

second_half_of_sent:
goto all the time, I love it!

first_half_of_sent:
I use
goto second_half_of_sent;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top