DEV Community

Discussion on: Is modern C better then Rust?

Collapse
 
pauljlucas profile image
Paul J. Lucas

Templates in C via macros is problematic for several reasons (see here among many other places) — which is why C++ implemented a true, first-class template mechanism. Also, errors are impossible to read since everything gets folded onto a single line. If you want templates, just use C++, not C.

Collapse
 
sucuturdean profile image
David

I forgot to add that clang and gcc tell you on what line in the preprocessor was the error which is so useful.

Collapse
 
sucuturdean profile image
David • Edited

If you have preprocessor errors, you can ask the compiler to give you the preprocessed files that you can examine with your error codes. I understand that this is time consuming and that's why I made them if anyone needs them.

Collapse
 
pauljlucas profile image
Paul J. Lucas

Everything is not folded into a single line, that is just false ...

C11 standard §5.1.1.2 ¶ 1.2:

Each instance of a backslash character (\) immediately followed by a new-line character is deleted, splicing physical source lines to form logical source lines.

So a multi-line macro where each line ends with a backslash is folded into a single line.

Templates in C++ aren't that good also because they created template meta programming which should be it's own language ....

So offering flexibility by allowing (but not requiring) template meta-programming makes them bad? And it's not clear what a template-meta-programming-only language would be useful for.

Thread Thread
 
sucuturdean profile image
David • Edited

Well what I meant with template-meta-programming-only language is something like the preprocessor in c and c++, but with type checking. Like that you can see what the output of templates is and if you don't know template meta programming still understand what is going on(plus it could be useful if it was made to work with multiple programming languages). That claim about C11 standard it's true and I am sorry for the fact that I said that it's false, I should have researched more into it before saying it's false(I edited that part out so that it doesn't spread fake news).

Collapse
 
sucuturdean profile image
David

And it's not that a programmer wants templates, somethimes you need templates for simple things like vectors, options and other. Templates in C++ aren't that good also because they created template meta programming which should be it's own language, not in C++ so that people can flex with their knowledge. The whay that they sould be is like generics in other languages.