473,728 Members | 1,619 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 6432
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
1258
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
1701
by: in | last post by:
I hate static variables and methods. Hate them. HATE THEM AAAAAAAAAAAAAAAAAAAAAAA!!!!!!!!!!!!!!!!!!!!!!!!!!!
7
1544
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
7663
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
1579
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
1483
by: Steven T. Hatton | last post by:
#
40
3123
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
8899
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
8757
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
9418
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
8124
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
4524
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
4790
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3235
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
2
2651
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2160
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.