Yea, C has lots of gotchas, and its minimal sanity checking also means it is very easy to mess things up and not know about it for a long time. Also, its single, unified namespace can be a big pain in the but
It's not entirely a single unified namespace. Using the static
keyword, you can restrict a global variable's scope to the current compilation unit. ie: if you declarestatic int temp1;
in multiple .c files, all linked together, then each .c fill will have its own unique temp1 variable. Similarly for functions. So each .c file can essentially have its own namespace (albeit not a conveniently as more modern languages).
C++ has many of the same gotchas as C does plus like 3 times as many on top of it. C++ is very powerful though.
C++ gets a lot of bad rap these days, so let me defend it a bit...
C++ fixes a lot of the basic gotchas of C because it is much more strongly typed. Even if you're writing a straight C program, there's almost no good reason not to compile it as C++ just for the better typing protection.
A lot of C++'s gotchas are because it leans towards "we'll give the programmers the power and flexibility to do almost everything, even if that will also allow them to shoot themselves in the foot" and is also a is a "kitchen sink" language. It layers all sorts of newer concepts (ie: overloading, classes, single AND multiple inheritance, templates) on top of the existing C language, all while retaining 95+% C back-compatibility, keeping all these different programming methodologies viable, and being suitable for adapting to everything from the latest supercomputer down to a real-time embedded soft-core FPGA processor that has only 1 megabyte of RAM and no multithreading or virtual memory.
That last bit is a lot of the reason C++ lacks a lot of the built-in high level features that many other more-focused modern languages have.
Now, my least favorite language that I actually worked with is FORTRAN 77. I had to port a large engineering application written partly spaghetti-style by non-programmers from F77 to C++. GOTO's. No data structures. Nearly everything global. 3-way conditional branching. Specialized math functions that don't exist outside of FORTRAN. What a nightmare.