50 points · by optimalsolver · 5y ago · 77 comments
Yet its major compilers are written in C++ nowadays, and C++ is the main language for GPGPU computing, including the memory model used by NVidia on their cards.
I suggest some benchmarks updates to the author.
For practical purposes, it is C.
https://www.youtube.com/watch?v=VogqOscJYvk
Future of ISO and CUDA C++
https://developer.nvidia.com/gtc/2020/video/cwe21284-vid
Thrust, the CUDA C++ template library
https://docs.nvidia.com/cuda/thrust/index.html
Optix, single-ray shader programming model using C++, and ray Tracing acceleration using RT Cores.
https://developer.nvidia.com/optix
Phew, so many wrappers yet to list.
Being able to write code for one will not confer immediate productivity in the other.
I wonder if there even is a language where something like this IS required. Most of the languages I know are case-sensitive yet the case doesn't mean anything specific in any of them, the case seemingly always is a matter of style.
This should have been formulated as:
You must declare a function as a prototype if you use the function before its definition appears in the code.
It's not just main but all functions.
What can pay-off is learning to read C. Node.js, Firefox, Postgres, Linux are all written in C/C++ so if you ever want to really understand what's going on or have to debug a nasty bug, then you will need to be able to find your way around these code-bases.
E.g. I think the size of my WASM demos is quite reasonable for what they do:
https://floooh.github.io/tiny8bit/
https://floooh.github.io/sokol-html5/
However, AssemblyScript is also a pretty good choice for this type of stuff from what I'm hearing (while for instance languages with a complex runtime like C# are not).
These are things that are not directly useful, but help you have a better mental model of how your language of choice actually works.
I think it’s good to at least play with C and understand how memory management and pointers in C work, but I don’t think I would recommend you go out of your way to learn C or spend any significant amount of time writing it. At the end of the day it’s just another tool in the toolbox. I would recommend the book Code, by Petzold, if you want to really want to explore computers at a low level in a friendly format.
Directly to machine code, not assembly.
-Embedded/cyber-physical systems software (firmware dev)
-Driver development (applies to Win/macOS/UNIX/iOS/Android)
-Contributing to the Linux kernel/OS dev in general
-Contributing to many large OSS projects (Apache, ffmpeg)
-Exploit/malware dev/reverse engineering
-Emulator development
you'd need to learn C.
Is it useful as a web developer? Only if you want to write extensions to Python in C or step away from the web developer label and learn systems programming.
At least these are not uninitialised variables.
// Shorthands for multiple declarations:
int i1 = 1, i2 = 2;
float f1 = 1.0, f2 = 2.0;
int b, c;
b = c = 0;
Edited:..
After 1hr of posting my original comment, I noticed that there many opinions here.I should have added why I think this is bad. Readability and maintenance. I would rather it have one line per declaration like the following..
int i1=2;
int i2=2;
Each variable easier to be changed, and reading it is clearer as there are no ambiguity to its type.A common error I have see from "the multiple declarations in the single line" construct is that changing the type impacts all the variables whereas the intention was only for the first variable.
C has been around long enough to develop multiple competing paradigms for how to format source code, each with copious existence proofs that "Good Code" can be written in them. Conform to what you're maintaining, don't start fights.
void function_1();
Most people coming from other languages (like C++) will probably think that this is identical with "void function_1(void)", but without the explicit void argument list, the compiler will not warn if the function is accidentally called with parameters."Warn if a function is declared or defined without specifying the argument types."
https://godbolt.org/z/8qYeK89rh
It's only an error in C++, but not in C, and the warning for this isn't included in the usual "-Wall -Wextra" set.
char *s = "foo", *t = "bar";
A beginner might forget to add the asterisk in `*t` (especially if the first declaration is written `char*` with no space on the left of the asterisk). Similarly with multiple types: char *p = "foo", **q = &p, *z[2] = {"foo", "bar"}, *(*f)(const char*) = strdup;
This is correct and an intermediate C programmer won't have too much trouble parsing these, but in the interest of clarity, it makes sense to put each declaration on a separate line.If you find yourself needing a lot of local variables, that's often a bad sign anyway, since it implies that the function has a lot of state to manage. In that case, you might want to rethink your implementation to make it less complex, or restructure the code to make it more managable.
int i1 = 1;
int i2 = 2;
The "usual footgun" is: int i1, i2, i3 = 0;
Only i3 will be initialized in this case. And since one needs to write out the assignments anyway, adding the type for each variable doesn't hurt either.(today's compilers usually have uninitialized-warnings for this though, but sometimes people forget to add a -Wall to their compiler options, especially beginners, and then get stuck on such trivial problems).
I
can't
read
your
comment,
could
you
split
your
words
into
separate
paragraphs?
And if there are no objective facts, then maybe we could just stop calling other peoples' preferred style nasty and "bad habits" as if it were objective.
Nope, it's very unexpected. Because parity check can now return 3 outcomes.
(-3) % 2; // => -1
Having self learned C devs do a big, complex program is an invitation for security vulnerabilities.
Most of the time people find themselves fighting against the language, and struggling to have the program simply not to crash.
If you see that, you start to think how much those guys would have time left to ensure anything like input sanitation, or code hardening in general.
>Most of the time people find themselves fighting against the language, and struggling to have the program simply to ...
compile.
My sincere thanks for the book.
Advanced C usage remaining a black magic is not strength, it's weakness. This assures that attackers will always have a significantly stronger upper hand against industry's salaryman developers.
With C, what you see is what you get. I don't see how that can possibly be black magic.
Most microcontrollers are ARM Cortex-M and are programmed with a recent GCC toolchain
https://devblogs.microsoft.com/cppblog/c11-and-c17-standard-...
(it has a solid subset of C99 since around VS2015 though, just _Generic was missing - and ignoring VLAs, which have been "dropped" in later C standards anyway).
IME C coders are a fairly relaxed bunch on average, definitely more relaxed than some of the younger and more "radical" language communities in C's neighborhood.