Slashdot Mirror


What's To Love About C?

First time accepted submitter edA-qa writes "Antiquated, clunky, and unsafe. Though beloved to some, C is a language that many choose to hate. The mass opinion is indeed so negative it's hard to believe that anybody would program anything in C. Yet they do. In fact a lot of things, even new things, are programmed in C. The standard was recently updated and the tools continue to evolve. While many are quick to dismiss the language it is in no danger of disappearing."

7 of 793 comments (clear)

  1. Re:because by localman57 · · Score: 5, Informative

    No, he's right. On systems where your constants exist in a different medium than your variables (such as microcontrollers where variables are in RAM but constants are in flash), declaring a string as const or not const can have a big impact on what resources you eat up. Typcially, there's often a #pragma or non-standard keyword such as ROM that goes along with this.

  2. Re:Good habits by localman57 · · Score: 5, Informative

    Exactly. My company does a lot of different things from embedded systems to web interfaces, and, generally speaking, the C guys write better Java code than the Java guys write C code.

  3. Re:because - by 19thNervousBreakdown · · Score: 4, Informative

    That's because there is no difference! I think you meant:

    char* const foo;

    for the second one. const modifies the item to the left, unless it occurs at the beginning of the line, in which case it modifies the item to the right.

    --
    <xml><I><am><so><damn>Web 2.0</damn></so></am></I></xml>
  4. Re:Maybe because it compiles down to the metal... by slew · · Score: 4, Informative

    ...and not some VM? Most of the popular languages these days are all dynamic. And they are very convenient and nice. But if you actually want to know what the machine is actually doing, and want to have a say in such things, C is the way to go.

    I mean, unless you want to, you know, use pascal or fortran or something.

    Although "C" compiles down really very close to the metal, so does "C++" (and a host of other more modern languages). However, it's not that easy to take that next step to the metal. In between is a machine that virtualizes the registers (using register renaming techinques), virtualizes the memory (using difficult to predict caching, translation, and ordering operations), and reorders the instructions (speculation, branch target hiding, etc), and runs in a sandbox (under the os which is timeslicing between tasks and faulting and swapping in memory translations and maybe even simulating some instructions).

    Knowing what the machine is actually doing is often a mythical quest down the rabbit hole. Although I'm a big fan of "C+" (what I call the c++ subset that doesn't have all the crapola that I don't use**), I'm under no illusion that all you are really doing with C is using a more predictable translation strategy (e.g., static compile time translation) rather than some magical "metal" commanding language.

    ** +objects, +const, +templates, +-stl (some are okay), -overloading, -virtual inheritance, -rtti, -boost, etc...

  5. Re:because - by AuMatar · · Score: 4, Informative

    And the funny thing is that most people who write const char* foo really want char const * const foo. You don't want either the pointer or the data pointed at to change. However, almost nobody knows that, so even those who do just use the weaker const char* so people understand the code.

    --
    I still have more fans than freaks. WTF is wrong with you people?
  6. Re:because - by DanTheStone · · Score: 4, Informative

    Thank you. "const" modifies the thing that preceded it. Iff nothing precedes it, it modifies the first thing that follows it. It's not terribly complicated.

  7. Re:because by dmbasso · · Score: 4, Informative

    Don't know much about C, do we? ;-)

    He does, you not so much.

    If I saw the above declaration, I wouldn't be at all surprised to see a later command like:

    post = "second"; // Or perhaps some computed value

    If the declaration had contained a const, this would be a syntax error, since the variable post has been declared a constant.

    Nopz, what was declared as constant is the memory the pointer is pointing to. Example:

    1: void f() {
    2: const char *a="bla";
    3: a = "blu";
    4: a[0] = 0;
    5: }
    >gcc -c t.c
    t.c: In function ‘f’:
    t.c:4:2: error: assignment of read-only location ‘*a’

    Tip: avoid using snarky comments. When you're wrong it makes you look specially stupid.

    --
    `echo $[0x853204FA81]|tr 0-9 ionbsdeaml`@gmail.com