HEAR, HEAR!!! [Pounds fist on table repeatedly]. I have been dying for this since gcc added the nonstandard extension and then C99, seems a lifetime ago, codified it in the C standard. What the HELL, guys. With all the wang-yanking ivory tower crap they did implement in C++11 and 14, much of it very hard work to master using, let alone implementing, is there any way in hell you can blame us for calling you out on the immature assholery of not simply copying this dead-simple feature from C99?
This should have been the number one improvement put into C++03. Leaving it out of 11 was unforgiveable, and leaving it out of 14 is goddam obstruction.
And yeah, I agree with you, gcc not adding it as a nonstandard C++ extension is sick. Particularly if clang and maybe Microsoft joined them and they all tried to shame the C++ standards committee.
This does not address your question specifically, but C++14 fixes some glaring holes in C++11. Well, one hole for damn sure. They clean forgot to put std::make_unique in C++11, even though std::unique_ptr was there. The hole was obvious to anyone who saw std::make_shared and then went to try and look up its obvious complement.
It was also high time and way beyond high time they added binary constants. Frustrating as hell they STILL found it too hard to support binary formatting in iostreams, though. Evidently it was too hard to add such a dead simple and obvious thing as std::bin, analogous to std::hex. So we already have a hole to fondly hope C++17 (sigh) deigns to fill for us.
Err, the implication is that you can also write C++ that is not guaranteed to be maintainable by anybody short of a complete master, which even Bjarne says he is not. I think it is fair to estimate that the number of complete C++ masters in the world is in the single to double digits; no more. It may be you can identify another programming language for which that holds true. I don't think I can.
Other successful computer languages do not have that problem. Any competent C programmer can maintain any C code, and the same for python and Java. Perl is arguable; the problem is not complexity but opaqueness.
Most of the people who complain about C++ are busy maintaining legacy C++ codebases, typically written before even C++98, making all of the worst possible decisions, ignoring best practices, etc. C is harder to make visibly screwed up, which is why people think it's better, even though it's really just that C makes it easier to write subtly broken code. For example, every obvious way to deal with integer overflow will break on particular sets of compiler optimizations, because C sticks it's fingers in it's ear and says "LALALALALA INTEGERS DON'T OVERFLOW LALALALALA I'M ELIDING YOUR SECURITY-CRITICAL OVERFLOW CHECKS LALALALALA".
You do understand that integer overflow is not buffer overflow, right? Integer overflow has absolutely nothing to do with security.
Yes, I DO live in a country with a wildly corrupt government that repeatedly lies to me and regularly unburdens many people's basic human rights. I live in the USA.
Funny thing, though. My IQ is greater than 10 (fine; I did not lose the genetic lottery), and I CHOOSE not to be profoundly ignorant. I know that amidst all those negatives, health measures are a good thing, not some underhanded nefarious attempt to harm the people when those in charge could far more easily and efficiently just mow us down with bullets.
BTW, your example had a buffer-off-by-one bug even before you changed 1024 to 512. You didn't manage the terminating null.
Your second example first of all gives a compile error: "error: cannot convert ‘int*’ to ‘char*’ in initialization" "char *b = &a;"
It also gives another warning in gcc 4.9 even if you don't compile with -Wall. "warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]" "b = "abcd";"
Thank you. It is a very tenable objection. I am not fully persuaded, but it is food for thought.
My counterpoint is that iota, used in the context of std::iota rather than the evil "using std" at the top, is something that is easily looked up. OTOH, I wouldn't suggest C++ programmers could be expected to know about iota and a million other standard library resources.
The problem with having a std::sort(std::vector) template is that then you need one for all other applicable containers, and if a new container is written, then you have to write a new std::sort template as well. I think that is the reason it is expressed using iterators, which is really very powerful. The template approach is something you have to buy into whole-heartedly.
I've programmed C for a little over 30 years and C++ off and on since a little over 20 years ago. While the basics of C are long completely ingrained, doing it right does still take a little concentration - like using snprintf instead of sprintf - C does have its own useless backward-compatibility cruft nobody should ever use any more. C++ is a whole different story. Doing anything at all properly with it requires enormous concentration and constant reference. There are a very few masters of C++ who make it seem like it is easy for them - but not for me:-)
usually a genuine troll is discernible by his lack of being willing to debate or defend that opinion
That's a tough call. For example the present state of political discourse in the US is a prime example of pathological polarization. People have heard it all. Their viewpoint is their viewpoint. Usually it is a very strong one, and nobody else can change it. You can't convince a socialist that government power is the enemy, and you can't convince a capitalist that corporations are the enemy. So they rage at each other. You can substitute any other polar situation and the same thing applies: pro-ACC vs anti-ACC, gun rights vs gun control, etc.
It is very widespread. Now, you can label it "troll" behavior, but irreconcilable polarization is what it really is. The "troll" tag is not constructive, because it implies that it is a fringe personality problem, and it's not. The general breakdown in civil discourse is very frightening, and it's absolutely not an internet-only problem. The anonymity and insulation of the internet just remove the inhibitions people have against engaging what they know are irreconcilable differences.
This was not always the case. I remember the climate of 50-60 years ago. People had very strong beliefs and disagreements then, too, but it was possible for opposites to engage. The two poles didn't see each other as outright un-American traitors.
Sorry; brain leaped to alternate reality in that last line. It's gonna have to be a BIT more work, but not much:
int i { 0 };
for (auto x : myVec) x = i++;
It's hard drive manufacturers that insisted on decimal instead of binary prefixes, not RAM makers. In fact, it's fairly difficult to make RAM to decimal prefixes.
Why is it difficult to make a 2.147483648 GB stick of RAM but easy to make a 2 GiB stick of RAM?
I think you can relax a little. Despite the hysteric headline, DARPA is no police agency, not even a standards agency. It's a research agency. Only good can come from them turning some of their high power brains toward the problem of authentication.
I am MUCH more interested in Broadwell DESKTOP chips. I'm using a Haswell Xeon E3-1245v3 in a server now, and it speedsteps all the way from 3.4 GHz down to 100 MHz under light load. Ivy Bridge only stepped down to 800 MHz, and Sandy Bridge only stepped down to 1.6 GHz.
How did you decide that the People's Republic of China is a dictatorship? Most consider it a representative democracy. It certainly considers itself such. Nominees for Local People's Congresses can be selected not only by the Communist Party, but also other parties, and even by individual voters, properly seconded. The popular election of same is then made by secret ballot. Recall elections are provided for. The Local People's Congresses in turn elect the National People's Congress, and the NPC in turn elects national leaders.
OK, it's not a pure democracy, but there are damn few of those.
If you want to match oppression for oppression, there are a lot worse than PRC, and a fair number arguably better. I submit it's around average.
What you call Arab Spring got triggered by hate-filled religious fervor and a thirst to enforce religious orthodoxy and punish the bejesus out of everyone less than 100% religiously orthodox, plain and simple.
So from your own description the City of London Police report to a council which is a "bunch of corporate stooges", yet somehow that doesn't make it in effect a private police force?
Since there are no actual people in the city, just corporations and commuters
According to Wikipedia, the City of London has a resident population of about 7000 and a commuting.working population of about 300,000. There are certainly many "actual people in the city". Or do you believe Wikipedia is wrong on this score?
Both residents and representatives of the businesses vote in the elections. It is true that the former are outnumbered by the latter.
HEAR, HEAR!!! [Pounds fist on table repeatedly]. I have been dying for this since gcc added the nonstandard extension and then C99, seems a lifetime ago, codified it in the C standard. What the HELL, guys. With all the wang-yanking ivory tower crap they did implement in C++11 and 14, much of it very hard work to master using, let alone implementing, is there any way in hell you can blame us for calling you out on the immature assholery of not simply copying this dead-simple feature from C99?
This should have been the number one improvement put into C++03. Leaving it out of 11 was unforgiveable, and leaving it out of 14 is goddam obstruction.
And yeah, I agree with you, gcc not adding it as a nonstandard C++ extension is sick. Particularly if clang and maybe Microsoft joined them and they all tried to shame the C++ standards committee.
This does not address your question specifically, but C++14 fixes some glaring holes in C++11. Well, one hole for damn sure. They clean forgot to put std::make_unique in C++11, even though std::unique_ptr was there. The hole was obvious to anyone who saw std::make_shared and then went to try and look up its obvious complement.
It was also high time and way beyond high time they added binary constants. Frustrating as hell they STILL found it too hard to support binary formatting in iostreams, though. Evidently it was too hard to add such a dead simple and obvious thing as std::bin, analogous to std::hex. So we already have a hole to fondly hope C++17 (sigh) deigns to fill for us.
Err, the implication is that you can also write C++ that is not guaranteed to be maintainable by anybody short of a complete master, which even Bjarne says he is not. I think it is fair to estimate that the number of complete C++ masters in the world is in the single to double digits; no more. It may be you can identify another programming language for which that holds true. I don't think I can.
Other successful computer languages do not have that problem. Any competent C programmer can maintain any C code, and the same for python and Java. Perl is arguable; the problem is not complexity but opaqueness.
You do understand that integer overflow is not buffer overflow, right? Integer overflow has absolutely nothing to do with security.
Yes, I DO live in a country with a wildly corrupt government that repeatedly lies to me and regularly unburdens many people's basic human rights. I live in the USA.
Funny thing, though. My IQ is greater than 10 (fine; I did not lose the genetic lottery), and I CHOOSE not to be profoundly ignorant. I know that amidst all those negatives, health measures are a good thing, not some underhanded nefarious attempt to harm the people when those in charge could far more easily and efficiently just mow us down with bullets.
Your example is one of what an amateur C hacker might do. No competent C programmer duplicates numeric literals in the same context.
Professional standards demand e.g.:
const size_t buffsz = 1024;
char *dst[buffsz+1];
strncopy(dst, src, buffsz);
BTW, your example had a buffer-off-by-one bug even before you changed 1024 to 512. You didn't manage the terminating null.
Your second example first of all gives a compile error:
"error: cannot convert ‘int*’ to ‘char*’ in initialization"
"char *b = &a;"
It also gives another warning in gcc 4.9 even if you don't compile with -Wall.
"warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]"
"b = "abcd";"
Thank you. It is a very tenable objection. I am not fully persuaded, but it is food for thought.
My counterpoint is that iota, used in the context of std::iota rather than the evil "using std" at the top, is something that is easily looked up. OTOH, I wouldn't suggest C++ programmers could be expected to know about iota and a million other standard library resources.
The problem with having a std::sort(std::vector) template is that then you need one for all other applicable containers, and if a new container is written, then you have to write a new std::sort template as well. I think that is the reason it is expressed using iterators, which is really very powerful. The template approach is something you have to buy into whole-heartedly.
I've programmed C for a little over 30 years and C++ off and on since a little over 20 years ago. While the basics of C are long completely ingrained, doing it right does still take a little concentration - like using snprintf instead of sprintf - C does have its own useless backward-compatibility cruft nobody should ever use any more. C++ is a whole different story. Doing anything at all properly with it requires enormous concentration and constant reference. There are a very few masters of C++ who make it seem like it is easy for them - but not for me :-)
I was really serious when I recommended python.
That's a tough call. For example the present state of political discourse in the US is a prime example of pathological polarization. People have heard it all. Their viewpoint is their viewpoint. Usually it is a very strong one, and nobody else can change it. You can't convince a socialist that government power is the enemy, and you can't convince a capitalist that corporations are the enemy. So they rage at each other. You can substitute any other polar situation and the same thing applies: pro-ACC vs anti-ACC, gun rights vs gun control, etc.
It is very widespread. Now, you can label it "troll" behavior, but irreconcilable polarization is what it really is. The "troll" tag is not constructive, because it implies that it is a fringe personality problem, and it's not. The general breakdown in civil discourse is very frightening, and it's absolutely not an internet-only problem. The anonymity and insulation of the internet just remove the inhibitions people have against engaging what they know are irreconcilable differences.
This was not always the case. I remember the climate of 50-60 years ago. People had very strong beliefs and disagreements then, too, but it was possible for opposites to engage. The two poles didn't see each other as outright un-American traitors.
You're right of course. You can use either auto& or int&. But you'd better be sharp :-) It's the only one I didn't test (until now).
But don't you agree that using iota to dispose of the init loop entirely is the best choice?
OP AC is a moron. He's not gonna get it.
Sorry; brain leaped to alternate reality in that last line. It's gonna have to be a BIT more work, but not much:
int i { 0 };
for (auto x : myVec) x = i++;
Look, if you want a language that is elegant and simple yet powerful and complete - but slow - IMHO, use Python.
However, in your C++11 example it would help if you actually leveraged C++11:
vector<int> myVec(100);
iota(myVec.begin(), myVec.end(), 0);
Here is an actual complete program:
#include <iostream>
#include <numeric>
#include <vector>
int main()
{
std::vector<int> myVec(100);
std::iota(myVec.begin(), myVec.end(), 0);
for (auto x : myVec) {
std::cout << x << '\n';
}
}
even in your own C++11 example, the sensible way to use auto would have been:
for (auto x : myVec) myVec[i]=i;
A lot less of that cursed verbosity, no? So in fact, in your picked example, C is not more concise and readable, after all.
Sorry to say, I flat out don't believe you.
Why is it difficult to make a 2.147483648 GB stick of RAM but easy to make a 2 GiB stick of RAM?
I think you can relax a little. Despite the hysteric headline, DARPA is no police agency, not even a standards agency. It's a research agency. Only good can come from them turning some of their high power brains toward the problem of authentication.
Maybe because "noone" is NOT A FUCKING WORD and tags the user as illiterate.
I am MUCH more interested in Broadwell DESKTOP chips. I'm using a Haswell Xeon E3-1245v3 in a server now, and it speedsteps all the way from 3.4 GHz down to 100 MHz under light load. Ivy Bridge only stepped down to 800 MHz, and Sandy Bridge only stepped down to 1.6 GHz.
How did you decide that the People's Republic of China is a dictatorship? Most consider it a representative democracy. It certainly considers itself such. Nominees for Local People's Congresses can be selected not only by the Communist Party, but also other parties, and even by individual voters, properly seconded. The popular election of same is then made by secret ballot. Recall elections are provided for. The Local People's Congresses in turn elect the National People's Congress, and the NPC in turn elects national leaders.
OK, it's not a pure democracy, but there are damn few of those.
If you want to match oppression for oppression, there are a lot worse than PRC, and a fair number arguably better. I submit it's around average.
The original expression is far less confusing and awkward than your try. Sorry.
What the hell do you think an o-ring is?
Do you really believe that? Even iIf your transistor is 100 atoms high, it still can't be less than 1 atom wide or deep.
Er, the square root of 2 is 0.707, not 0.66.
What you call Arab Spring got triggered by hate-filled religious fervor and a thirst to enforce religious orthodoxy and punish the bejesus out of everyone less than 100% religiously orthodox, plain and simple.
So from your own description the City of London Police report to a council which is a "bunch of corporate stooges", yet somehow that doesn't make it in effect a private police force?
According to Wikipedia, the City of London has a resident population of about 7000 and a commuting.working population of about 300,000. There are certainly many "actual people in the city". Or do you believe Wikipedia is wrong on this score?
Both residents and representatives of the businesses vote in the elections. It is true that the former are outnumbered by the latter.