473,659 Members | 2,996 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Things I hate about C++


Okay here we go, I feel it's about time people conversed about the bullshit
aspects of C++ (including the bullshit stuff brought forward from C). I'll
begin with a few of my own grievances:
1) The whole "function declaration Vs object definition" fiasco, which
results in the following (temporary creating) syntax:

Blah poo = Blah();
2) How string literals are not const (even though they are!), for instance:

void Blah(char* const p_k)
{
*p_k = '4'; //Opps!
}

int main()
{
Blah("Hello");
}
3) How arrays decay to pointers...
The following is possible:

unsigned &r = *new unsigned;
But the following is not:

unsigned (&r)[10] = *new unsigned[10];

That's all I can think of right now!
-JKop
Jul 22 '05
111 6400
Phlip wrote:
<snip>
2) How string literals are not const (even though they are!), for


instance:
void Blah(char* const p_k)
{
*p_k = '4'; //Opps!
}

int main()
{
Blah("Hello");
}

That's to avoid breaking poor quality C code (like I used to write).

<snip>

And to keep already broken poor quality C code broken.

Actually, whether this works tends to be platform independent. AIUI in
DOS/Windows it tends to work but on Unix-based platforms it tends to bus
error. But even when it does work, it's a bit undefined when the same
string literal may be reused. The compiler ought to at least issue a
warning whenever a string literal is passed into a non-const char *.

Stewart.
Jul 22 '05 #11
* Richard Herring:

#if hypothetical::h as_public_copy_ ctor<T>::value
T t = T();
#else
T t;
#endif

maybe?


The preprocessor does its processing first, then the "real"
compiler (or, the compiler must ensure a result as if that
was the case).

--
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?
Jul 22 '05 #12
In message <41************ ***@news.indivi dual.net>, Alf P. Steinbach
<al***@start.no > writes
* Richard Herring:

#if hypothetical::h as_public_copy_ ctor<T>::value
T t = T();
#else
T t;
#endif

maybe?


The preprocessor does its processing first, then the "real"
compiler (or, the compiler must ensure a result as if that
was the case).

True. Well, I did say "maybe" ;-)

Any suggestions for using template trickery to get the same effect?

--
Richard Herring
Jul 22 '05 #13
JKop wrote:
Okay here we go, I feel it's about time people conversed about the bullshit
aspects of C++ (including the bullshit stuff brought forward from C). I'll
begin with a few of my own grievances:
1) The whole "function declaration Vs object definition" fiasco, which
results in the following (temporary creating) syntax:

Blah poo = Blah();
Actually the real problem is that the
Blah poo;
should universally declare a default initalized Blah, regardless of
what type Blah really is.

None of your headstanding would be necessary if C++ was consistant
in it's behavior.

2) How string literals are not const (even though they are!), for instance:
Yes, the deprecated conversion to lose the const, was a bone thrown to
the whiners in the standardization process. Some didn't want string
literals to be const at all.


3) How arrays decay to pointers...
More specifically, that arrays are bastard types. They don't behave
like other types, in regard to copying and assignment. Once upon a
time both array's and structs lacked proper behavior in this regard.
Dennis fixed structs but the array-to-pointer decay workaround had
already been instituted and rather than bite the bullet and fix it,
C stuck with it.

The following is possible:

unsigned &r = *new unsigned;
But the following is not:

unsigned (&r)[10] = *new unsigned[10];


Actually, the bigger issue here is also that C++ dynamic allocation is
also braindead in that it was designed to model the stupid-assed
behavior of malloc / free in a slightly more type safe manner.

Jul 22 '05 #14
Phlip wrote:
Blah poo = Blah();

A> you don't need to do that.


You do if you want a default initalized poo and Blah is of POD type.
B> the compiler can optimize the temporary away
Perhaps.

C> the compiler cannot optimize the = away, so if it's
private that should not compile outside Blah's
internal scop
Huh?

The problem JKop is tripping over is that despite the changes
in the 2003 update to the language, you STILL have to know the
exact nature of Blah to figure out how to default initailize
it properly. We now have three freaking different initialzation
schemes:
1. POD
2. non-POD without a user defined default construcotr
3. non-POD with a user defined default constructor.

There is not even a syntactic device (which JKop has been chasing)
that allows you to universally work around this insanity. It makes
template programming in general a bit difficult if you don't PUNT like
the STL does and insist that you should always be able to copy/assign
a default constructed object to do the initailization.

That's to avoid breaking poor quality C code (like I used to write).

It doesn't avoid breaking it, it just avoids keeping it from compiling
allowing the undefined behavior present to latently sneak by.

Jul 22 '05 #15
Richard Herring wrote:
If you're really so concerned about this non-issue, why not just give
your class a constructor that takes a (dummy) argument? Then you can
just write

Blah foo(99);

and all your problems are over.


Until you want to write a template and don't know what the
nature of Blah really is. There's no way to univerally default
initialize an automatic variable in C++. It's a language defact.
Jul 22 '05 #16
JKop wrote:

Okay here we go, I feel it's about time people conversed about the
bullshit aspects of C++ (including the bullshit stuff brought forward from
C). I'll begin with a few of my own grievances:


You really need to look at things in perspective. C has been hugely
successfull. When it was created, the ideas and technology that exists
today were not even dreamed of. A Gig of RAM? A 180 Gig harddrive? Most
people would have laughed in your face if you told them that was possible.
Sure there are some less than ideal features, but to describe these as
"bullshit" is kind insulting to the creators of C.

1) The time it takes to find information such as which function raises an
unsigned int to an exponent of unsigned int, returning unsigned int.

2) The # symbol, and all that is associated with it.

3) No support for introspection.

4) The lack of standard file name extensions.

5) The flat namespace of the Standard Library.

6) The lack of a library resolution mechanism

That's all I can think of right now. The second item is by far the biggest
gripe I have.
--
"If our hypothesis is about anything and not about some one or more
particular things, then our deductions constitute mathematics. Thus
mathematics may be defined as the subject in which we never know what we
are talking about, nor whether what we are saying is true." - Bertrand
Russell

Jul 22 '05 #17
JKop wrote:
Okay here we go, I feel it's about time people conversed about the bullshit
aspects of C++ (including the bullshit stuff brought forward from C). I'll
begin with a few of my own grievances:
1) The whole "function declaration Vs object definition" fiasco, which
results in the following (temporary creating) syntax:

Blah poo = Blah();

You do not have to use that. Use Blah poo; If you want to zero
initialise a POD type do it explicitly,
E.g.

Blah poo = {0};


2) How string literals are not const (even though they are!), for instance:

void Blah(char* const p_k)
{
*p_k = '4'; //Opps!
}

int main()
{
Blah("Hello");
}
char * const p; is a const pointer, which cannot point anywhere else.

const char *p; is a pointer which points to a const object.
const char * const p; is a const pointer which cannot point anywhere
else, and points to a const object.




3) How arrays decay to pointers...
The following is possible:

unsigned &r = *new unsigned;
But the following is not:

unsigned (&r)[10] = *new unsigned[10];

What's that suppose to mean? You can do:

unsigned &r = *new unsigned[10];
However why do this tricky stuff?
That's all I can think of right now!

My suggestion is have a slow thorough read of an up to date ISO C++
book, like "Accelerate d C++".

--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 22 '05 #18
JKop wrote:
Any thoughts on why the following is illegal?:
struct Blah
{
int a;
char b;

double* p_c;
};
int main()
{
double r;

Blah* p_poo =

new Blah = {5, 't', &r};
}

For the same reason that 6=5; is illegal too.

Not supported by the language.
My suggestion is have a slow thorough read of an up to date ISO C++
book, like "Accelerate d C++".

--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 22 '05 #19
Ioannis Vranos wrote:
JKop wrote:
Okay here we go, I feel it's about time people conversed about the bullshit aspects of C++ (including the bullshit stuff brought forward from C). I'll begin with a few of my own grievances:
1) The whole "function declaration Vs object definition" fiasco, which
results in the following (temporary creating) syntax:

Blah poo = Blah();

You do not have to use that. Use Blah poo; If you want to zero
initialise a POD type do it explicitly,
E.g.

Blah poo = {0};


A POD non-virtually inheriting a POD is still a POD, but can't use that
notation.

JKop is recommended to write complete constructors, and to encapsulate
low-level things that need PODs behind interfaces that ensure they are used
correctly.

And if Blah::operator= (Blah const &); were private, that expression wouldn't
compile outside Blah's internal scope, even though operator= should not
during construction.
My suggestion is have a slow thorough read of an up to date ISO C++
book, like "Accelerate d C++".


Jee, I don't think we ever recommended this to JKop before!!

--
Phlip
http://industrialxp.org/community/bi...UserInterfaces
Jul 22 '05 #20

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
1256
by: gf gf | last post by:
Is there a better, more FP style, more Pythonic way to write this: def compute_vectors(samples, dset): vectors = {} for d in dset: vectors = return vectors Namely, I'd like to get rid of the initilization
10
1696
by: in | last post by:
I hate static variables and methods. Hate them. HATE THEM AAAAAAAAAAAAAAAAAAAAAAA!!!!!!!!!!!!!!!!!!!!!!!!!!!
7
1536
by: Alexa | last post by:
Hi Everyone, As a user, which ad format you hate the most and which you like the most? A) Top banner B) Google AdSense C) In-content rich media box D) Vibrant Media IntelliTxt I will summarize findings here when I got enough votes.
92
7634
by: Jeffrey P via AccessMonster.com | last post by:
Our IT guys are on a vendetta against MS Access (and Lotus Notes but they've won that fight). What I can't understand is, what's the problem? Why does IT hate MS Access so much. I have tried to find out who it is that actually wants to get rid of it, but I can't find anyone who will admit to trying to get rid of it. Nevertheless, I'm always hearing about how their "phasing it out" or "getting rid of it". Because no-one owns up I can't...
14
1575
by: CMM | last post by:
Do the developers of Visual 2005 actuall use it??? There's lots of great things in VS2005 (mostly related to the outstanding work done on the CLR)... but in general the LITTLE THINGS totally drag it down.. especially the slightly-improved-but-not-all-that-much IDE. I waited for 3 years for this? Who's in charge of this mess? 1) Editing a web form in the designer... I think I'm totally misunderstanding the usage of CSS stylesheets and...
10
1481
by: Steven T. Hatton | last post by:
#
40
3109
by: PJ6 | last post by:
I want to rant, but I'm too busy at the moment. Who else hates working in C#? What's your biggest pet peeve? Paul
0
8335
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8851
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8747
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8528
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8627
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7356
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4335
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1976
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.