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 111 6449
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
* 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? 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 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
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
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 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 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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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
|
by: in |
last post by:
I hate static variables and methods.
Hate them.
HATE THEM
AAAAAAAAAAAAAAAAAAAAAAA!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
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.
|
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...
|
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...
| |
by: Steven T. Hatton |
last post by:
#
|
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
|
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...
|
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...
|
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,...
|
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...
| |
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |