General > General Technical Chat

How many people code in C these days, and if so, why?

<< < (62/99) > >>

IDEngineer:

--- Quote from: SiliconWizard on May 11, 2020, 01:44:30 pm ---I have personally never run into such a compiler bug. That would look like a bug on a *very* basic C feature.... I still want to draw people's attention to the dangers of comparing C "booleans" with a constant.... So, beyond the style question, I think you should be very careful with this.
--- End quote ---
I totally agree. And I am very careful. For example, I use only the boolean constants defined by the compiler, which reduces (but does not eliminate!) the risk.

To be clear, I wasn't necessarily encouraging this style. It was just a response to the whole "boolean" subthread, which triggered this memory for me.

Speaking of weird bugs: Years ago when I wrote device drivers and applications for Win32 on Windows, the holy and worshipful Visual Studio {grin} and its C/C++ compiler had a bug where #include statements in the very first line of a source file were ignored. I kid you not. It was 100% repeatable. I still leave line 1 of my source files blank as a result of THAT bug in my past. I bet I have more little subconscious quirks like that and the boolean== thing that I've acquired over the years and just don't think about, because I got burned at some point.

floobydust:
Reading Ritchie's The Development of the C Language paper (from GNU C readings) helped me realize again - the language goes back to the early 1970's and is flawed and cannot fix things due to the legacy code out there it's always had to support. Live on PDP-7. I guess this is why you instead just come up with a new programming language.

I've always hated the C language's lack of type-checking, which is intentional as the academics like polymorphism which is a shit storm for embedded systems.

I've always hated the language's lack of range-checking, where you index outside an array's bounds - this has countless bugs and punches to memory locations, enabled countless buffer-overrun virus invasions, to this day. I understand it's too much overhead to check during run-time like other languages, but it's a huge danger.

Why compile:

--- Code: ---char myArray[10];
int myTrollLife[10];


myArray[10] = '?';
myTrollLife[50] = 1241248798798798719986720;

--- End code ---

I wish the C compilers worked a little harder and caught obvious noob mistakes, instead of catering to legacy or whatever it is that commands ignoring the obvious.


I've always hated the language's silly freedom i.e.


--- Code: ---if (flaps = true) {
  Boeing737Max(); // goodby all passengers and thanks for compiling.
}

--- End code ---

Why allow assignments within a conditional expression? Just crazy.

I'm not trying to be perfect here in my examples or my rant- but it's hilarious how dangerous the C language is, and it doesn't need to be.
All the fanboys expect a perfect programmer but these three issues are huge, in my view and been around for decades as I remember.

bd139:
I tend to write conditionals "yoda style" as I have indeed shafted myself with that.

if (true = flaps)

... error: lvalue required as left operand of assignment

But you know, testing is important too. So is static analysis (coverity). So is runtime analysis (valgrind etc). So is fuzzer (afl). And obviously unit and integration level testing otherwise how the hell do you know what you've written actually even works correctly from a semantic perspective.

Nominal Animal:

--- Quote from: floobydust on May 11, 2020, 08:00:09 pm ---I'm not trying to be perfect here in my examples or my rant- but it's hilarious how dangerous the C language is, and it doesn't need to be.
All the fanboys expect a perfect programmer but these three issues are huge, in my view and been around for decades as I remember.

--- End quote ---
FWIW, I do agree.  C really isn't that good, which is why I feel so strongly about its standardization committee; they're the ones that could help make it better.. but don't.

It's just that there are some use cases where we don't have anything better than C yet.

Sal Ammoniac:

--- Quote from: Kjelt on May 03, 2020, 05:55:57 pm ---By the way, ever tried reprogramming 300Mlocs of C code that is tested and prooven over 25 years, and then start all over in another language?
How many thousands of SW engineers and hundreds of millions of $ would that cost ?

--- End quote ---

Not anything approaching 300Mlocs of code, but I did run into a similar situation at my last job. We had a series of products that used a C code base that was ~15 years old. This was embedded code running on 16-bit and 32-bit microcontrollers with limited FLASH and RAM and consisted of perhaps 125Klocs of C. The code was mature, and while by no means bug free, bugs reported by customers were rare. This code was written by senior engineers who were primarily EE types rather than CS types and they all had been at the company for >20 years.

A few years ago the company was growing and hired a few more software people, mostly guys right out of university, but a few senior ones as well. These new guys collectively took one look at the existing code and promptly declared it broken, purely because it wasn't written in C++. They mounted a campaign to start moving everything to C++ while the old timers dug in their heels and resisted these efforts. I left the company right around the time the C++ crowd was starting to win some minor battles and the old timers were starting to get weary of the infighting and just letting the newcomers have their way.

So what would the C++ advocates gain by rewriting this code base in C++? Very little. The existing code was working, was well-understood, had few real bugs, and had made the company hundreds of millions of dollars over the years. Rewriting it in C++ would have taken perhaps 10-20 man-years of effort and would have resulted in a code base with hundreds of bugs, many of which had been exterminated in the C code base years and years ago. It would have been harder to understand by many of the people who had to interact with it and maintain it (primarily customers and application engineers, who were typically not CS types and who were comfortable with C but not with C++).

The industry is littered with the burned-out wrecks of companies who thought rewriting their bread and butter products in a newer, shinier language was a good idea.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

There was an error while thanking
Thanking...
Go to full version
Powered by SMFPacks Advanced Attachments Uploader Mod