What I don't like in C and C ++

Please do not read professional C / C ++ programmers).

In the article, I express my point of view, if you disagree - justify in the comments.
The purpose of this article is to point out the shortcomings of C and C ++, which I really do not like and encourage you to use the new version of the language or maybe even offer some ideas for improving the standard.

Well, it's time to rekindle the holivar.

I think everyone knows that it’s awesome lines in C ++. Especially if we are talking about the old type, in the new string a lot has been fixed and improved, but there is still no Unicode support (!).

In the standard C ++ 20, they seem to be about to introduce unicode strings.

C ++ 20! And this is despite the fact that C ++ has existed since 1983 .

Open your favorite IDE and try to compile the following code:

#include<iostream>#include<cstdio>intmain(){
  charstring [256];
  std::cout << "Привет: ";
  gets(string); 
  std::cout << "Вывод: " << string;
  return0;
}

UPD1: the commentator says that the cracks are only on Windows. That's for sure, I forgot to write about it.
But still unpleasant.

I compiled in Dev Cpp, the GCC compiler.

Compile and see:



Good screen output, right?

Now let's replace char string [256] with char * string.

I’m not saying that this should work, but the compiler should have thrown the error to its maximum.

We got a work program that hung.
It would be better if the compiler threw an error.
And the whole garbage is that the compiler is not enough to compile it, it has not yet
issued a warning.

Here's another joke:

#include<iostream>usingnamespacestd;
intmain(){
    int arr[100]={};
    cout<<arr[101]<<endl;
    return0;
}

What do we expect? The compiler will tell us that it is impossible to access 101 array elements, since there are only 100 elements. But we compile, run and see ... 32765 (at least on my hardware).

Hmm.

Now let's test this code:

int i = 5;
i = ++i + ++i;
std::cout<<i;

What do you think he will bring?

The correct answer depends on the compiler.

In GCC it will be 14, but depending on the optimization flags.

And in another compiler it can easily be 12 ...

I think everyone knows that in C and in the pluses there is a lot of syntactic sugar, which is not always needed.

For example, std::cout<<4["string"];this is a valid code.
It outputs n, as well as std::cout<<"string"[4];

Hello, right?

And now about the patient.
C ++ and network.
This is 2 sooo badly matched concepts.
Try to just download the image of the cat from your favorite site using the standard C ++ library.
This was not possible until the adoption of the C ++ standard 17.
In the same standard library you cannot work with JSON.
Excellent comment about this.
In general, working with JSON in C ++ is like a nightmare.
Source .
Do you think the condition will always be false?

if(sizeof ('a') != sizeof (char)){
//do something
}

No, you are mistaken.

If you compile it as a C ++ project, then the condition is likely to fail.
Should not. [1]
And if like a C project, then in that case sizeof ('a') == sizeof (int).
That's it.
[1] In general, many different C and C ++ compilers are also a problem.
Because a lot of solutions are non-standardized and they will work only in certain compilers.

For example, 128 bit numbers in C ++. In gcc and clang there is the type __int128, while in Visual Studio it is not, because it is not a standard. Or, for example, strings in Visual Studio.

String^ MyString3 = "Hello, world!"; //попробуйте скомпилировать в GCC

Or, for example, in the old Borland C ++ Builder you can code written in Object Pascal.
And there are many such moments.

Of particular pain is the lack of a list of C and C ++ packages.

What follows from this? Use the new version of C ++, for example C ++ 17 and some problems will be solved.

I must say that in the nearest competitor C ++ - Rust there are not most of the problems from this list, for example, there is a wonderful cargo, but of course it is not perfect either.

And what problems C and C ++ do you know?
Write in the comments.

UPD: Many people seem to have misunderstood my article:
In no case do I want to criticize C / s ++ and say write on the plant.
Just pointing out the flaws in s / s ++, because they got a bit of themselves.

Everything has its drawbacks, I just shared my thoughts.
UPD2:

In the comments, many people write that OS works this way and in general these are features. You guys are wrong.
The same proof that you can make a system programming language in which it is not so easy to shoot yourself in the foot.

It’s just that C / C ++ is full of solutions that nobody can fix, because it can break backward compatibility.

And yes, this is my opinion, it is subjective .

If you do not agree - better comment, and not stupidly minus, because the opinion of all of us is
subjective.

Also popular now: