473,915 Members | 4,599 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 #1
111 6489
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:
Oh, dear. You have not shown much promise respecting C++, yet you want C++
to respect you.
1) The whole "function declaration Vs object definition" fiasco, which
results in the following (temporary creating) syntax:

Blah poo = Blah();
A> you don't need to do that.

B> the compiler can optimize the temporary away

C> the compiler cannot optimize the = away, so if it's
private that should not compile outside Blah's
internal scope.
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).
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];
Acolyte of the Week question:

What's this for?

template<class foo, size_t max>
inline size_t
get_count(foo const (&array)[max])
{
return max;
}

Where can you use it? Where can't you use it? How can you improve it?
That's all I can think of right now!


There are plenty of serious issues beyond these things that one could 'lint'
away.

For example, the 'new' you wrote will leak.

(I know I know - the OS Memory Fairy will clean it up...)

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

1) The whole "function declaration Vs object definition" fiasco, which
results in the following (temporary creating) syntax:

Blah poo = Blah();
A good compiler will not create a temporary here, but you're right: the
C syntax is a fiasco, and IIRC acknowledged as such by the creators.

2) How string literals are not const (even though they are!),
Right. That's old C compatibility for you.

for instance:

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

int main()
{
Blah("Hello");
}
Incorrect. The argument of function Blah should be

void Blah( char const* p_k )

for the intended const'ness effect.
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];
A better (or worse!) example is perhaps
typedef unsigned UnsignedArray[10];

UnsignedArray &r = *(new UnsignedArray);
Again, that's the C heritage.

That's all I can think of right now!


Uhm, well, there's much more. That's the price for compatibility.
Without the compatibility I doubt that C++ would have been very
successful.

--
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 #3
Oh, dear. You have not shown much promise respecting C++, yet you want
C++ to respect you.
I neither give respect to, nor wish to receive respect from, what does not
qualify as an organism.
1) The whole "function declaration Vs object definition" fiasco, which
results in the following (temporary creating) syntax:

Blah poo = Blah();


A> you don't need to do that.

No comment. No, actually, comment: Bullshit.

B> the compiler can optimize the temporary away

The compiler *may* optimize the temporary away.

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

If "what" is private? I presume you're on about the copy contructor.

If you're referring to "=", as in the assignment operator, then don't
respond.

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

.. . .and this makes it non-bullshit because?

For example, the 'new' you wrote will leak.

Please don't be stupid. I also didn't mention in my last post that I'd drunk
water in the last 3 days. Does that mean I'm on my way out soon?
-JKop
Jul 22 '05 #4
void Blah(char* const p_k)
{
*p_k = '4'; //Opps!
}

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


Incorrect. The argument of function Blah should be

void Blah( char const* p_k )

for the intended const'ness effect.

You misinterpreted my intention. Here's what I'm doing:
void Blah(char* p_k)
{
*p_k = '4';
}

int main()
{
Blah("Hello");
}
The only reason I put:

void Blah(char* const p_k);
in my previous post is that I put in "const" wherever I can.
Regarding:
char* const p_k
The variable itself is "const", (my function may not and does not change
it), but what it points to is "non-const", (my function is free to change it
if it wishes... and it does!). The thing here is that while "Hello" is in
essence const, it still gets passed as a non-const argument.

So, in summation:

"Hello"

It's type is "char[6]". Note the absence of "const".

While contradictorily (...need me a dictionary...)

char* p = "Hello";

*p = '4';
-JKop
Jul 22 '05 #5

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};
}
-JKop
Jul 22 '05 #6
In message <uy************ *******@news.in digo.ie>, JKop <NU**@NULL.NULL >
writes
1) The whole "function declaration Vs object definition" fiasco, which
results in the following (temporary creating) syntax:

Blah poo = Blah();


A> you don't need to do that.


No comment. No, actually, comment: Bullshit.
B> the compiler can optimize the temporary away


The compiler *may* optimize the temporary away.


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.

--
Richard Herring
Jul 22 '05 #7
B> the compiler can optimize the temporary away


The compiler *may* optimize the temporary away.


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.


I want to be able to define a value-intialized object of *any* type.
AnyTypeUnderThe Moon poo = AnyTypeUnderThe Moon();
achieves this. But there's two problems:
A) A temporary.

B) The copy constructor may be private.
Then comes the argument: If the copy constructor is private, then there's a
constructor defined and so it's not a POD and so it doesn't matter if you
value initialize or not. But I want a universal syntax, such that the
following template will work with ALL types. It's not much to ask...

template<class T>
void GiveMeAnyType()
{
T t = T();
}
int main()
{
GiveMeAnyType<s td::ostringstre am>();
}
Compile error: Copy constructor is private.

-JKop
Jul 22 '05 #8
template<class T>
void GiveMeAnyType()
{
T t = T();
}
int main()
{
GiveMeAnyType<s td::ostringstre am>();
}
Compile error: Copy constructor is private.

So far I have the following work-arounds:
Work-around 1:

template<class T>
void GiveMeAnyType()
{
T const &t = T();
}

Problem: It has to be const.
Work-around 2:

template<class T>
void GiveMeAnyType()
{
T &t = *new T();

delete &t;
}

Problem: I'm not sure if there's an efficiency or performance issue.

-JKop

Jul 22 '05 #9
In message <vm************ *******@news.in digo.ie>, JKop <NU**@NULL.NULL >
writes
B> the compiler can optimize the temporary away

The compiler *may* optimize the temporary away.
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.


I want to be able to define a value-intialized object of *any* type.

AnyTypeUnderTh eMoon poo = AnyTypeUnderThe Moon();
achieves this.


Ah. Now I see the problem - it isn't "your" class at all.
But there's two problems:

A) A temporary.

B) The copy constructor may be private.
Then comes the argument: If the copy constructor is private, then there's a
constructor defined and so it's not a POD and so it doesn't matter if you
value initialize or not. But I want a universal syntax, such that the
following template will work with ALL types. It's not much to ask...


Take a look at boost::type_tra its. It may not do exactly what you
require, but some work on those lines may yield what you need -
something on the lines of

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

maybe?
--
Richard Herring
Jul 22 '05 #10

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

Similar topics

6
1267
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
1721
by: in | last post by:
I hate static variables and methods. Hate them. HATE THEM AAAAAAAAAAAAAAAAAAAAAAA!!!!!!!!!!!!!!!!!!!!!!!!!!!
7
1556
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
7712
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
1596
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
1497
by: Steven T. Hatton | last post by:
#
40
3162
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
10039
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11354
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
10923
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...
0
10542
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
9732
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...
1
8100
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5943
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6148
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4778
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.