Slashdot Mirror


A New C Standard Is On the Way

Esther Schindler writes "Last year, Danny Kalev — a former member of the C++ standards committed — explained the new features in C++. Now, in C11: A New C Standard Aiming at Safer Programming, he shares an overview of the changes in C — 13 years after the ratification of the C99 standard. Kalev describes the goodies in C11, including multi-threading support, safer standard libraries, and better compliance with other industry standards."

305 comments

  1. Hmm by mholve · · Score: 2, Funny

    No wonder they're not popular. C99? C11? It should be "C... X!" :p

    1. Re:Hmm by K.+S.+Kyosuke · · Score: 2

      The only thing we know for sure is that the ultimate version will be C42. Also, C14 will be rather popular but all implementations will generate binaries that will randomly fail, and will trip off airport security systems if you have them in you mobile devices with you.

      --
      Ezekiel 23:20
    2. Re:Hmm by cpghost · · Score: 2

      The only thing we know for sure is that the ultimate version will be C42.

      But by then, we'd have lost the hardware to that software answer (unless someone still has a C64 in the attic)

      --
      cpghost at Cordula's Web.
  2. On the way? by TheRaven64 · · Score: 5, Informative

    It's not on the way, it was released last year. Both gcc and clang are already a good way along implementing it, and we've added a big chunk of the library support to FreeBSD libc already.

    --
    I am TheRaven on Soylent News
    1. Re:On the way? by Anonymous Coward · · Score: 2, Funny

      It's not on the way, it was released last year.

      C'mon, this is /. -- it's either a dupe or it's old news.

    2. Re:On the way? by shutdown+-p+now · · Score: 1, Redundant

      You'd think people would have figured that from it being called C11, too...

    3. Re:On the way? by Tough+Love · · Score: 5, Funny

      The "11" actually refers to how far you can turn up the volume.[1]

      [1] Quoted from Tough Love's Album of Unreliable Facts (c)

      --
      When all you have is a hammer, every problem starts to look like a thumb.
    4. Re:On the way? by shutdown+-p+now · · Score: 5, Insightful

      This being C, 11 would mean that you can turn the volume from 0 all the way up to 10.

    5. Re:On the way? by Bacon+Bits · · Score: 5, Funny

      No, you can turn the volume up as high as you want, but it's only defined for 0 to 10.

      --
      The road to tyranny has always been paved with claims of necessity.
    6. Re:On the way? by DdJ · · Score: 1

      Both gcc and clang are already a good way along implementing it, and we've added a big chunk of the library support to FreeBSD libc already.

      So, um, how is that inconsistent with "on the way"? The standard may be written, but the implementation is still "on the way", no?

    7. Re:On the way? by Anonymous Coward · · Score: 0

      really?!

      volume = (unsigned) -1;

    8. Re:On the way? by bug1 · · Score: 2

      Y3k bug strikes again, he meant C3011

    9. Re:On the way? by dAzED1 · · Score: 1

      because the standard isn't "on the way." It is already here. Design comes before implementation in any tech program that is more advanced than building a throw-away mini webapp or webpage.

    10. Re:On the way? by Anonymous Coward · · Score: 1

      Its defined in all the range, you silly. It's only that it wraps around modulo 11. Unless you use signed volumes, that is. Then it really is undefined beyond 10.

    11. Re:On the way? by jones_supa · · Score: 1

      This being C, 11 would mean that you can turn the volume from 0 all the way up to 10.

      Not necessarily. Usually the "goes to 11" pun is applied to knobs which also go from 0 to 10 by default.

    12. Re:On the way? by Anonymous Coward · · Score: 0

      No, you can turn the volume up as high as you want, but it's only defined for 0 to 10.

      i doubt this ... http://www.youtube.com/watch?v=EbVKWCpNFhY

    13. Re:On the way? by Anonymous Coward · · Score: 0

      Pun???

    14. Re:On the way? by saider · · Score: 1

      C11 goes up to three. Or nine. Or seventeen. What's the base?

      Or perhaps it does go to ten, but since 4 bits need to be allocated for storage, values eleven to fifteen are reserved for future expansion.

      --


      Remember, You are unique...just like everyone else.
    15. Re:On the way? by shutdown+-p+now · · Score: 1

      C11 goes up to three. Or nine. Or seventeen. What's the base?

      10, of course, since there's no leading 0 or 0x.

  3. D? by Anonymous Coward · · Score: 1

    Is that finally D?

    1. Re:D? by chinton · · Score: 2

      No, it's finally P.

    2. Re:D? by sconeu · · Score: 1

      If this version is P, then when will L finally come out?

      --
      General Relativity: Space-time tells matter where to go; Matter tells space-time what shape to be.
    3. Re:D? by viperidaenz · · Score: 1

      pseudo methamphetamine?

    4. Re:D? by Anonymous Coward · · Score: 3, Informative

      no -- C was based on B, which was based on BCPL. So first came BCPL, then B, then C, therefore the next one will be P.

    5. Re:D? by stderr_dk · · Score: 2

      No, it's finally P.

      Is that the same as NP?

      --
      alias sudo="echo make it yourself #" ; # https://pipedot.org/~stderr & http://soylentnews.org/~stderr
  4. C11???? by highphilosopher · · Score: 5, Funny

    That's great! I'm still using C4, and every time I compile my code blows up!

    1. Re:C11???? by jd · · Score: 2

      I hear C5 was dog-slow and users suffered humiliation.

      --
      It's a small world and it smells funny; I'd buy another if it wasn't for the money; Take back what I paid (SoM)
    2. Re:C11???? by Anonymous Coward · · Score: 5, Funny

      Plus, as using C-14, I am able to determine the compiling date of any given code.

    3. Re:C11???? by Anonymous Coward · · Score: 0

      --insert ~ath comments here--

    4. Re:C11???? by freeze128 · · Score: 1

      C11 is a stupid name. They should call it C02.

    5. Re:C11???? by GoodNewsJimDotCom · · Score: 4, Funny

      I am still using the programming language made a long time ago C3PO. You'd be surprised how similar it is to Jawa.

    6. Re:C11???? by idontgno · · Score: 3, Funny

      It's really only useful for controlling 'vaporators and binary loadlifters.

      --
      Welcome to the Panopticon. Used to be a prison, now it's your home.
    7. Re:C11???? by Anonymous Coward · · Score: 2, Funny

      I've been using CB. All functions are called by the new "breaker.breaker" operator--and don't even get me started on the crazyvariable names you have to use...

    8. Re:C11???? by Imagix · · Score: 3, Informative

      Uh, why C02 when is was standardized in 2011? The headline is simply wrong. C11 isn't "On the way". It's already here, and has been here for > 5 months. You _might_ have an argument for C0B. (Long-running joke. C++0x was the next C++ standard, and there was a joke that they hoped that the x wasn't going to be a hex digit....)

    9. Re:C11???? by Sduic · · Score: 5, Funny

      The worst part was the C4 standard was prepared with SemTeX.

      --
      *this space intentionally left blank
      "One of the four pointers saying 'come and see', and I saw, and beheld a white
    10. Re:C11???? by Anonymous Coward · · Score: 0

      I prefer to program in Jar Jar :-)

    11. Re:C11???? by Anonymous Coward · · Score: 0

      *woooosssshhhh* that's the sound of carbon dioxide rushing over your head trying to escape from that really bad joke.

    12. Re:C11???? by SlashV · · Score: 1

      whoosh

    13. Re:C11???? by Anonymous Coward · · Score: 0

      I can't think of a witty comment, so I'll just say "Woosh!"

    14. Re:C11???? by Anonymous Coward · · Score: 0

      I'm using a C, AC-130 specifically >> C4

    15. Re:C11???? by sg_oneill · · Score: 1

      Call it C02 and half of the conservative blogosphere is going to start running aroiund in circles decrying it as some sort of strange communist conspiracy.

      --
      Excuse the Unicode crap in my posts. That's an apostrophe, and slashdot is busted.
    16. Re:C11???? by SuperKendall · · Score: 1

      And the liberal half will be running around in circles trying to ban it.

      --
      "There is more worth loving than we have strength to love." - Brian Jay Stanley
    17. Re:C11???? by Anonymous Coward · · Score: 0

      And nothing of any import will be lost.

    18. Re:C11???? by Anonymous Coward · · Score: 0

      I guess all that Carbon Dioxide filled air whooshed right over your head.

    19. Re:C11???? by Alex+Belits · · Score: 2

      --insert ~ath comments here--

      not thii2 2hiit...

      --
      Contrary to the popular belief, there indeed is no God.
    20. Re:C11???? by Anonymous Coward · · Score: 0

      wasn't that written in a semantic Web programming language?

    21. Re:C11???? by Anonymous Coward · · Score: 0

      Whoosh...

    22. Re:C11???? by dintech · · Score: 5, Funny

      Since I'm using C64, I find I have to be careful with my memory usage.

    23. Re:C11???? by Anonymous Coward · · Score: 0

      My beer is safe then, phew!

    24. Re:C11???? by 228e2 · · Score: 2

      You. Get out.

      --
      Since when does being a Socialist mean 'someone who has a different opinion than me'?
    25. Re:C11???? by Anonymous Coward · · Score: 0

      That would be a gas!

  5. Slow Adoption of Current Standards by otterpop81 · · Score: 1

    I wish new standards could be adopted more quickly. In Visual Studio it wasn't until 2010 that I could even get basic C99 headers like stdint.h.

    1. Re:Slow Adoption of Current Standards by JustNiz · · Score: 4, Informative

      Blame Microsoft, not the standards committee.
      GCC had it ahead of time.

    2. Re:Slow Adoption of Current Standards by Anonymous Coward · · Score: 5, Informative

      Visual Studio added stdint.h not to comply with C, but to comply with the pending new C++ standard. Microsoft has publicly declared that they have no intention of supporting anything past C95 (basically ANSI C circa 1989 with a few tweaks).

      So some of the coolest things in C99 and C11, like named initializers, compound literals, etc, will never be in Visual Studio, because C++ has refused to adopt those features from C.

    3. Re:Slow Adoption of Current Standards by ackthpt · · Score: 0

      Blame Microsoft, not the standards committee.
      GCC had it ahead of time.

      Takes Microsoft longer because they have not only the compiler to think about but all your friendly (annoying) pop-up help on everything

      Plus, give Steve Balmer a chance to give the dev team a pep talk and an Executive Chair Toss

      --

      A feeling of having made the same mistake before: Deja Foobar
    4. Re:Slow Adoption of Current Standards by shutdown+-p+now · · Score: 5, Informative

      Visual Studio is explicitly a C++ implementation, and does not focus on C support. It has what effectively amounts to C89 support, but that's a legacy thing. Any support for C99 and C11 features is purely accidental, and usually happens when some header is required by both C99/C11 and C++11 (hence why it's just headers and never language features).

      In the meantime, other implementations, which actually care about C as well and C++ - like gcc or clang - add C11 support fairly quick.

    5. Re:Slow Adoption of Current Standards by Anonymous Coward · · Score: 2, Informative

      I feel your pain on this, but MS has said time and again that they don't bother with the C standard because they make a C++ compiler, not a C compiler. So they only bother complying with C++98/03 and C++11. Any C99 compliance we get is essentially just due to the shared standards that C99 has with C++11. This isn't to say I excuse this decision, just a little insight as to why it took so long to get stdint.h.

    6. Re:Slow Adoption of Current Standards by Ungrounded+Lightning · · Score: 4, Insightful

      Microsoft has publicly declared that they have no intention of supporting anything past C95

      I gave up on Microsoft back when Byte magazine was in, or recently beyond, single-digit issue numbers.

      A letter to the editor complained about Microsoft's support of their FORTRAN compiler: There was a bug in the floating point format handling that a customer needed to use. After several iterations of bug reports and fix requests, Microsoft had told the guy that not only had they not fixed it yet, but they were never going to fix it. IMHO that meant Microsoft had an institutional issue with customer support and adherence to standards.

      Avoiding Microsoft software and products has saved me immeasurable grief over the several decades since.

      --
      Bantam Dominique roosters crow a four-note song. Once you've heard it as "Happy BIRTHday" you can't NOT hear it that way
    7. Re:Slow Adoption of Current Standards by makomk · · Score: 2

      Of course, the "safer" C library string functions are already supported by Visual Studio because they're part of Microsoft's cargo-cult approach to security. You know, the one where they're so busy making everyone rewrite all their existing code to new APIs that they don't think about little details like whether it's a good idea to hand out Microsoft certificates which have code-signing permissions for no real reason and can be used to sign fake Windows updates to anyone and everyone. And where they don't bother to upgrade the signing process for those certificates to something better than MD5.

    8. Re:Slow Adoption of Current Standards by serviscope_minor · · Score: 5, Interesting

      Yes, I totally think we should rewrite the linux kernel in C++

      I don't know if you're trolling, but I agree, it is the logical thing to do.

      Linux has many, many C++ features implemented in an ad-hoc and poorly specified way in C.

      It is very heavy on OO style with derived classes and virtual functions.

      TRhe C style objects are complex and require init and cleanup functions to be called.

      They have imlemented type-generic macros in order to reduce code duplication effectively.

      Basically, C++ takes those three things and integrates them into the language in a standard way so that everyone uses them in the same way, you get sane error messages and compiler support. C++ has one additionmal advantage that it has one global vtable per class, so each instance has a single pointer to the vtable. Linux's C-style OO has each instance having a pointer to every virtual method otherwise the syntax would be too unpleasant. This makes it less memory efficient in C and increaces the cache footprint.

      The only thing worse about C++ would be that the compile times would be increased.

      But that's a tiny price to pay for fewer bugs and faster code.

      --
      SJW n. One who posts facts.
    9. Re:Slow Adoption of Current Standards by RaceProUK · · Score: 1

      IMHO that meant Microsoft had an institutional issue with customer support and adherence to standards.

      Or they figured supporting the twelve people still using that compiler would be too expensive. Only MS knows for sure.

      --
      No colour or religion ever stopped the bullet from a gun
    10. Re:Slow Adoption of Current Standards by Anonymous Coward · · Score: 1
    11. Re:Slow Adoption of Current Standards by serviscope_minor · · Score: 2

      Why do people keep modding up this old, tired tripe.

      Just about everything in the article is either correct and very out of date (amazingly, the world of C++ has changed in the last 20 years) or was never true in the first place.

      --
      SJW n. One who posts facts.
    12. Re:Slow Adoption of Current Standards by Viol8 · · Score: 2

      "Linux's C-style OO has each instance having a pointer to every virtual method otherwise the syntax would be too unpleasant. This makes it less memory efficient in C and increaces the cache footprint."

      Err, C++ vtables require a double pointer dereference - the C version requires 1. That alone is a good enough reason not to use C++. Aside from that when you;re writing an OS you want to know exactly how your memory is set up and used, not hope the compiler doesn't fuck something up when it tries to get clever.

      Stick to application programming and leave kernel dev to people who know what they're doing.

  6. Drops the most important feature of C99 by Anonymous Coward · · Score: 5, Interesting

    C11 will make var arrays, one of the most widely used C99 features, optional due to pressure from Microsoft, who refuses to implement C99.

    1. Re:Drops the most important feature of C99 by shutdown+-p+now · · Score: 1

      Do you have any references that this is "due to pressure from Microsoft"? Last I checked, VC++ team has plainly stated that they are simply not interested in working on vanilla C, so why would they care about what is and isn't in C11?

    2. Re:Drops the most important feature of C99 by Tough+Love · · Score: 1

      That's easy to fix, just don't use Microsoft's crappy compiler. The days when it could compete effectively with GCC are long gone, and LLVM is coming up fast too.

      --
      When all you have is a hammer, every problem starts to look like a thumb.
    3. Re:Drops the most important feature of C99 by Tough+Love · · Score: 3, Funny

      Last I checked, VC++ team has plainly stated that they are simply not interested in working on vanilla C, so why would they care about what is and isn't in C11?

      Given that Microsoft's implementation of C++11 also sucks, exactly what is the VC++ team interested in working on?

      --
      When all you have is a hammer, every problem starts to look like a thumb.
    4. Re:Drops the most important feature of C99 by Anonymous Coward · · Score: 3, Interesting

      Which is ironic, because Microsoft's Visual Studio team has stated they have no intention of supporting anything newer than C95. I don't understand why Microsoft is even allowed representation on the ISO committee.

      And the bounds-checking API which Microsoft "contributed" is useless. It's clunky, and requires more boilerplate coding than just using the standard interfaces with proper bounds checking. Plus they added a completely new errno_t typedef, which will probably breaks tons of existing code. Not to mention that not even Microsoft supports the API. The Win32 precursor to Annex K is incomplete and inconsistent. In other words, Annex K is dead in the water. Microsoft won't support it, and the BSD and GNU libc take completely different approaches.

    5. Re:Drops the most important feature of C99 by shutdown+-p+now · · Score: 3, Informative

      For VS 2010, C++11 (then 0x) implementation was actually better than g++. It looks dated today because g++ has more frequent releases and it didn't take it long to catch up and overtake. Ditto for Clang.

      For VS 2012, yeah, it's lagging behind, mostly because a lot of time was spent on C++/CX language extensions for Metro. They did update existing features to be spec conforming - e.g. lambdas were previously implementing draft semantics which have changed in the FCD, so those were updated to match the latter. It also adds a bunch of minor stuff like range-for and strongly typed enums, and a good chunk of new libraries (most notably atomics, threads and futures). Here are the details.

      There is talk about doing a separate release later on specifically for VC++ to catch up with C++11 support. If you care about that, rather than just seeing it as an opportunity for some MS bashing, please add your vote here (I did).

    6. Re:Drops the most important feature of C99 by Anonymous Coward · · Score: 1

      Because it's no longer standard it won't be permitted under some government contracts, it's going to make my life suck a lot more starting next yet. :(

    7. Re:Drops the most important feature of C99 by Anonymous Coward · · Score: 2, Interesting

      Clang only ever looked dated compared to VC++ because the damn thing wasn't even finished yet. I doubt VC++ will ever catch up again with it, though. Clang in a relatively short time managed to go from barely able to compile C++03 to possibly the most complete implementation of C++11.

    8. Re:Drops the most important feature of C99 by Anonymous Coward · · Score: 1

      For C, maybe. For C++, MSVC has been superior to most other compilers.

    9. Re:Drops the most important feature of C99 by Anonymous Coward · · Score: 0

      For C++, MSVC has been superior to most other compilers.

      Except for correctness.

    10. Re:Drops the most important feature of C99 by Anonymous Coward · · Score: 0

      If you're talking about MSVC6 yeah.

    11. Re:Drops the most important feature of C99 by Anonymous Coward · · Score: 2, Informative

      If by "short time" you mean 5 to 6 years, okay. It was open sourced in 2007, but had been in development at Apple for longer than that.

    12. Re:Drops the most important feature of C99 by ericcc65 · · Score: 1

      C11 will make var arrays, one of the most widely used C99 features, optional due to pressure from Microsoft, who refuses to implement C99.

      This lists variable length arrays as mandatory. Is it wrong? http://en.wikipedia.org/wiki/C11_(C_standard_revision)

    13. Re:Drops the most important feature of C99 by jonwil · · Score: 2

      Having followed C++11 support in compilers, I can tell you that the C++11 support in even the latest version of Visual C++ (Visual C++ 2012 RC) is lagging behind both GCC and clang. To be fair, a lot of the lag is caused because Microsoft spent a lot of their resources in the VS2012 development cycle attempting to implement Variadic Templates (and not getting it done in time for the VS2012 release)

    14. Re:Drops the most important feature of C99 by ericcc65 · · Score: 1

      C11 will make var arrays, one of the most widely used C99 features, optional due to pressure from Microsoft, who refuses to implement C99.

      This lists variable length arrays as mandatory. Is it wrong? http://en.wikipedia.org/wiki/C11_(C_standard_revision)

      Nevermind, the column heading indicates it was mandatory in C99, but optional in C11. I agree, that is stupid as that was one of the best features of C99.

    15. Re:Drops the most important feature of C99 by gparent · · Score: 1

      Maybe he was talking about performance. It's only natural that GCC and clang are now ahead due to their more frequent releases. I don't really rely on MSVC++ (I find VS a great IDE, but I really don't care if I'm using MSVC++, GCC or clang/llvm to compile the code, but in a lot of benchmarks I've seen MSVC++ is significantly faster than GCC. I haven't seen anything much recent though.

    16. Re:Drops the most important feature of C99 by JDG1980 · · Score: 1

      That's easy to fix, just don't use Microsoft's crappy compiler. The days when it could compete effectively with GCC are long gone, and LLVM is coming up fast too.

      What if you want to use Direct2D or DirectWrite in your software? The last time I checked, GCC for Windows (MinGW) didn't support these APIs. Has this been fixed? Until you can use the full set of Windows APIs on the open compilers, many Windows programmers will have no choice but to use VC++.

    17. Re:Drops the most important feature of C99 by mfwitten · · Score: 1

      Lattner was hired by Apple in 2005 because of his work on LLVM at the University of Illinois at Urbana-Champaign. He worked on Clang at Apple; it to be open-sourced in 2007. So, I think you are exaggerating a bit.

    18. Re:Drops the most important feature of C99 by loufoque · · Score: 1

      For VS 2010, C++11 (then 0x) implementation was actually better than g++

      MSVC10 is very bad at standard conformance, even with C++98. It has so many bugs it's not even funny, notably in name lookup and overload resolution. When bugs are reported to them they refuse to fix them.
      GCC, on the other hand, has had very good C++ support for a long time and is only getting better.

    19. Re:Drops the most important feature of C99 by Anonymous Coward · · Score: 0

      To be honest, I prefered alloca, which both GCC and MSVC did and still do support. I don't see why the standards comittee has to invent new syntax for everything. Isn't the point of standardisation to formally specify what people were already doing?

      Also, why couldn't they make complex numbers optional? They really don't fit in the C language.

    20. Re:Drops the most important feature of C99 by Anonymous Coward · · Score: 0

      LOL GCC, and CLang are a joke, only decent compiler i ever tried is Intel C++ compiler (if you can afford it)

    21. Re:Drops the most important feature of C99 by TemporalBeing · · Score: 1

      VS2008 and VS2010 have come a long way. But you are correct - they still have a long way to go to match GCC's level of standards compliance.

      For example, It's rediculous that they only just introduced stdint.h in VS2010.

      --
      Truth is like the sun. You can shut it out for a time, but it ain't goin' away. - Elvis Presley (source: imdb.com)
    22. Re:Drops the most important feature of C99 by hazah · · Score: 1

      You're right, it's SOOOOO funny!

  7. Integer overflow! by Montreal · · Score: 5, Funny

    C99 -> C11, come on guys ...

    1. Re:Integer overflow! by Anonymous Coward · · Score: 1

      ASCII code 99: c
      ASCII code 11: Mars symbol

      [feminist conspiracy theorist]Clearly this is a sign that the C++ standards committee is biased against womyn!

    2. Re:Integer overflow! by Anonymous Coward · · Score: 1

      C revision naming is non-Y2K compliant!

    3. Re:Integer overflow! by Tanktalus · · Score: 2

      It should at least have been C111

    4. Re:Integer overflow! by Anonymous Coward · · Score: 0

      I agree completely. As so many of us in IT wasted^H^H^H^H^H^Hinvested a year of our life in Y2K remediation, it's good to know I'm not the only one who cringes when I see years abbreviated to 2 digits.

      I NEVER ABBREVIATE YEAR TO 2 DIGITS.

    5. Re:Integer overflow! by Anonymous Coward · · Score: 0

      [feminist conspiracy theorist]Clearly this is a sign that the C++ standards committee is biased against womyn!

      That would be one stupid feminist conspiracy theorist. We're talking about C, not C++.

    6. Re:Integer overflow! by LongearedBat · · Score: 1

      No, it ought to be C9A, which wouldn't be an integer overflow. But, damn, that's alot of versions.

    7. Re:Integer overflow! by monkeykoder · · Score: 1

      OMG!!! It's the Y2K bug the world is ending!!!! The Mayans were right!!!

  8. Re: by bleedingsamurai · · Score: 2

    The multi-threaded stuff sounds nice. But bounds checking, really? How difficult is it to check buffer size before copying?

  9. hrmph... by logicassasin · · Score: 1

    All the fuss over C, yet there's still no "H" programming language...

    --
    Fifty watts per channel, baby cakes.
    1. Re:hrmph... by Anonymous Coward · · Score: 0

      All the fuss over C, yet there's still no "H" programming language...

      But there is a Ch programming language...

    2. Re:hrmph... by jd · · Score: 1

      Personally, I think they should have named this standard MMXII.

      --
      It's a small world and it smells funny; I'd buy another if it wasn't for the money; Take back what I paid (SoM)
    3. Re:hrmph... by Anonymous Coward · · Score: 0

      I didn't know there was a second version of the MMX instruction set...

  10. Jeezus christ by JustNiz · · Score: 5, Funny

    If I wanted plastic scissors I'd use Java. Give me my scalpel back.

    1. Re:Jeezus christ by arkane1234 · · Score: 4, Funny

      Too many people have been randomly slicing people.

      --
      -- This space for lease, low setup fee, inquire within!
    2. Re:Jeezus christ by Anonymous Coward · · Score: 0

      gets() is not a scalpel. It's more like an electric chair marketed as children's toy.

      If you need strcpy() it's still there as well as "while (*d++=*s++) ;".

  11. Schools by Murdoch5 · · Score: 1

    It's time for school's to update what they teach for standard C, Even after C99 was released and C11 I had profs teaching C89, I think school's should follow suite with industry and upgrade.

    1. Re:Schools by Anonymous Coward · · Score: 1

      Your school should also teach the proper use of apostrophes.

    2. Re:Schools by BenoitRen · · Score: 0

      Did you also have professors that taught you to abuse the apostrophe?

    3. Re:Schools by Anonymous Coward · · Score: 0

      I believe the idiom is "follow suit", not "follow suite". I have no idea what "follow suite" is supposed to mean.

    4. Re:Schools by fnj · · Score: 1

      And the difference between suit and suite.

    5. Re:Schools by mattack2 · · Score: 1

      I think school's should follow suite with industry and upgrade.

      Apparently, schools need to teach the English language more thoroughly, too.

    6. Re:Schools by Murdoch5 · · Score: 1

      nope, I just don't care how I write. Great spelling and grammar is needed by authors and teachers, programmers only care about getting working, optimized code outputted.

    7. Re:Schools by Anonymous Coward · · Score: 0

      He is using them properly, following the A55 standard.

    8. Re:Schools by jeremyp · · Score: 1

      nope, I just don't care how I write.

      You don't give a fuck about your readers is how I read that sentence.

      Great spelling and grammar is needed by authors and teachers

      and is a goal to be aspired to by anybody who wants to communicate effectively.

      programmers only care about getting working, optimized code outputted.

      Which requires an almost anal attention to detail. I'm surprised it doesn't spill over into your English writing.

      --
      All I want is a secure system where it's easy to do anything I want. Is that too much to ask ~~ Randall Munroe
    9. Re:Schools by MattBecker82 · · Score: 1

      OK, I'll bite. Unintentional punctuation/spelling mistakes are understandable, yet you're clearly aware of what's correct and you still made the error. Your justification "I just don't care how I write" basically shows a complete lack of respect for those reading your text: you're essentially shifting the effort to correct your writing from you, the writer (once), onto the readers (multiple times). Plus, surely it takes less effort to write "schools" without the grocer's apostrophe, so I just don't get it.

      programmers only care about getting working, optimized code outputted.

      Speak for yourself. I care not only that my code is correct, but also that it is maintainable (optimization being important, but in most applications, less so than correctness/maintainability). Again, this is about having respect for those who are going to read what you write and not shifting work onto them because of your own laziness. It's not even just about altruism: a lot of the time it's your future self who will be maintaining the code, so you will be doing yourself a favour in the long run. What's that maxim? "Always write code as if the person who will maintain it is a psychopath who knows where you live."

    10. Re:Schools by Murdoch5 · · Score: 1

      I never said anything about maintainable code or readable code, you can't extract that because I don't care how I write that my code that it's unmaintainable or unreadable. I will grant you that unmaintable code is just a pile of useless lines and should only be used for toilet paper, however I never said I write unmaintainable code, I would assume if I did that someone over that last 10 years might of said something.

      Oh and I have actually programmed projects worth some weight, including multiple operating systems and a full radio astronomy control system.

      When it comes time to document my work I take a different stand but slashdot isn't a documentation site and it's not really professional in anyway, so as far as I'm concerned I'll just throw down what I want and submit.

    11. Re:Schools by fatphil · · Score: 1

      > programmers only care about getting working, optimized code outputted

      Thank got the groups I work with don't. They care about getting working, tested, maintainable code written. The fact that you even mentioned optimisation implies you're way too immature to understand software engineering yet.

      --
      Also FatPhil on SoylentNews, id 863
    12. Re:Schools by Murdoch5 · · Score: 1

      when did I say optimized mean't unmaintainable and untested ....... learning to read is always a good first step to mature software engineering.

    13. Re:Schools by fatphil · · Score: 1

      You didn't say tested, and you didn't say maintainable, which are important.
      You did say optimised, about which I refer you to Michael A. Jackson

      --
      Also FatPhil on SoylentNews, id 863
    14. Re:Schools by MattBecker82 · · Score: 1

      you can't extract that because I don't care how I write that my code that it's unmaintainable or unreadable.

      True, but I can't extract that it is maintainable either. I.e. because you've said you "only care about getting working, optimized code", implicitly you don't care about maintainability/readability. So there's no guarantee your code will be maintainable, and if it happens to be then it's not by design. My argument is that maintainability should be something programmers care about explicitly, and in most applications it should have higher priority than optimized code.

    15. Re:Schools by Murdoch5 · · Score: 1

      Okay but I still disagree with that, your code should run as fast and small ( memory ) as possible. Yes you need to be able to maintain it and test it and read it but having code that is slow, bulky and chugs along isn't any use to anyone. It can be the most maintainable code in the world but if it doesn't run as fast and optimized as possible then why are you calling yourself a software engineer.

      When you design a hardware embedded system, one of the things you look for is ways to cut size, power and cost. Well the same should go with software, I want the most optimized output I can get and then it's up the a true "software engineer" to be able to read code and understand it, just like an eletrical engineer is able to understand a schematic or circuit diagram.

    16. Re:Schools by MattBecker82 · · Score: 1

      I never said optimization wasn't important, only that for most applications it's less important than the maintainability of code - that's where we probably disagree. Of course, a lot of the time, there's no trade-off so it's possible to have fast working code that's also easy to maintain. Yes, "code that is slow, bulky and chugs along" is uselss but that's usually due to poor algorithm design / resource usage generally and not because efficiency has been specifically sacrificed for the sake of maintainability

  12. I don't get it... by xor.pt · · Score: 2, Insightful

    Why didn't they include some simple OOP features aswell? I understand this is a language for low level programming, and needs to be close to the metal, but many OOP features don't carry any significant overhead, and could just be avoided anyway.

    1. Re:I don't get it... by bleedingsamurai · · Score: 2

      If you want OOP and C go with C++ instead.
      C is supposed to be a high level assembly language, so simplicity and brevity are key.

      I find that Objective-C is pretty nice to. It is a very strict super-set of C that adds some OOP functionality and is no where near as complex as C++, in fact it is just a library or two sitting on top of a C compiler to interpret the OOP syntax. It is a shame that it is so tightly bound to Apple products.

    2. Re:I don't get it... by jd · · Score: 4, Insightful

      Because C is an ultra-clean procedural language. The entire purpose of using it is the purity. C with OOP can be found in ObjectiveC, C++, C# and D.

      --
      It's a small world and it smells funny; I'd buy another if it wasn't for the money; Take back what I paid (SoM)
    3. Re:I don't get it... by xor.pt · · Score: 1

      I would like _some_ OOP with C, C++ has too much, if I can frase it that way. GObject, Objective-C, Vala are good examples of projects trying to fill that gap but they come with their own set of drawbacks.

    4. Re:I don't get it... by bleedingsamurai · · Score: 2

      I see.
      Well, as far as a little OOP in C goes, what I have done is to create structures with whatever member data I need, and within those structures I place function pointers to emulate methods.
      If you see yourself doing a lot of that you can create functions that return pointers to your makeshift structure-class.
      Obviously you don't really get any advanced OOP stuff, but you can get simple inheritance using this method and a whole lot of encapsulation. If I'm not mistaken I think that C-family languages that support OOP actually do something like this behind the scenes.

      I guess I wouldn't mind a smidgen of OOP in C as long as they implement it through a library and not directly into the core language.

    5. Re:I don't get it... by shutdown+-p+now · · Score: 2

      You don't have to use all the features the language offers to you, you know. It is absolutely possible to use C++ as "C with some objects".

    6. Re:I don't get it... by xor.pt · · Score: 1

      Shouldn't the usefulness of potential features be considered aswell? This purity you speak of could just as easily be disturbed by the features added with C11, which are also present in other programming languages.

    7. Re:I don't get it... by PCM2 · · Score: 2

      No, I don't think "the usefulness of potential features" should be considered, if you're talking about something like bolting object orientation onto C. As other people have said, that has already been done, several times. If you want object-oriented C, use C++ or Objective-C. If you want to go even further that direction, use C# or even Java. The difference between an object oriented language and a structured procedural language like C is significant. Or maybe you could explain a little more what you mean by "some OOP." You seem to be arguing that C gives you nothing but C++ gives you too much -- but complaining that a language gives you too much of exactly what you're asking for is a pretty confusing way to make your case.

      --
      Breakfast served all day!
    8. Re:I don't get it... by Tough+Love · · Score: 2

      Because C is an ultra-clean procedural language.

      Haha, ultra-clean is not a term I would apply to either C or its demon child C++. Speaking as someone who has written hundreds of thousands of lines of both.

      --
      When all you have is a hammer, every problem starts to look like a thumb.
    9. Re:I don't get it... by BenoitRen · · Score: 1

      I don't find Objective C to be nice at all. It's a very ugly hack and I despised working with it.

    10. Re:I don't get it... by Anonymous Coward · · Score: 0

      If you're using a large C code base you can just use structs and function pointers like everyone else.

      I suspect, though, due to the way you are writing and asking the question, that you've never worked on a large C code base (which if they know what they are doing are already taking the good ideas from OOP methodology - but don't need the "class" keyword as a mental crutch).

    11. Re:I don't get it... by Bing+Tsher+E · · Score: 1

      Back in about 1995 the Slackware distros included a complete Objective-C build environment as a set of packages. That's where I first saw it. It was presented as a parallel option of about the same size and significance as the plain vanilla C build environment. How it turned into an Apple-owned deal I don't understand. It's from NeXT, isn't it? (almost everything good from Apple comes from outside the Infinite Loop)

    12. Re:I don't get it... by pipatron · · Score: 1

      There are however more stuff from C++ that could trickle back to C. Personally I'd like to see C inherit (pun intended) namespaces, better enums, default parameters values, and maybe templates from C++. C11 seem to have some basic template support in place at least, which is probably good enough.

      --
      c++; /* this makes c bigger but returns the old value */
    13. Re:I don't get it... by bleedingsamurai · · Score: 2

      It actually predates NeXT as well. XD It was developed by the founders of a company called Stepstone who originally licenced it to the NeXT company, then NeXT bought the rights to Objective-C and then Apple bought NeXT.

    14. Re:I don't get it... by Anonymous Coward · · Score: 1

      C++11 has a lot of nice features but it many ways it is playing catch up to Ada (see C++11 and Ada 2012 - renaissance of native languages? ). Too many view Ada as the "military programming language" but as safety and security become better understood Ada stands out.

      If you haven't looked at Ada or looked at it a while ago I would recommend trying one of the latest. You can get download GNAT Ada for free.

    15. Re:I don't get it... by fnj · · Score: 2

      So why don't you just use C++ then in the first place? No, I'm absolutely serious. You can basically take your existing C code and compile it with a C++ compiler in C++ mode, and with a very few exceptions it will compile and work just fine. Then you can start adding just those C++ features you want; no back-porting to C necessary.

      I mean, that was the WHOLE IDEA of C++ right from the beginning. There's nothing that says you need to use a single class in C++.

    16. Re:I don't get it... by cheesybagel · · Score: 2

      One issue is that the world is not a VAX anymore. Assembly language constructs can be way more complex than a lot of C statements. e.g. standard C has no concept of vector instructions.

    17. Re:I don't get it... by Anonymous Coward · · Score: 0

      C++ compilers whines too much.
      I don't want warnings/errors over silly type errors (passing unsigned char * as a char * etc).
      Sometimes this makes simple things hard: i mean pointer alignment in C can be done by
      ptr &= ~7;
      I have not found an as easy way to do that in C++.

      The list goes on. (C++ is a useful language in many ways, but there are reasons by long-time C programmers stick to C).

    18. Re:I don't get it... by Anonymous Coward · · Score: 0

      That line isn't going to get any less false the more you C++ zealots keep repeating it. If you have a modern C application that can compile as C++ with a few extra casts here and there, then you're really missing out on lots of useful new syntax and semantics in C, both standard and extended. I know it may surprise you C++ guys, but full-time C programmers don't secretly wish they were using C++. It's been right in front of us the whole time, and frankly we thought the whole thing would blow over until Google started mass producing legions of C++ zombies who are intent on porting every open source application to C++. Now its starting to get personal, because it's really hard to use C++ libraries in C, Perl, Python, Lua or basically anything other than C++, notwithstanding the mountains of wrappers, compiler options, and linker flags that allow access to a few useless entry points.

    19. Re:I don't get it... by jcdr · · Score: 1

      Right, but using C++ to do C is actually more frustrating, especially is you code a shared library intended to be used by C applications.

    20. Re:I don't get it... by shutdown+-p+now · · Score: 1

      Right, but using C++ to do C is actually more frustrating

      How so? It's almost a strict superset, and pretty much all cases where it ain't are better in C++, like no implicit cast to void*, or no need to use type tags or typedefs for structs/unions/enums.

      especially is you code a shared library intended to be used by C applications.

      The only catch I can think of here is that you'd need to use extern "C", but you can simply wrap your entire translation unit sans #includes into extern "C" { ... }. It won't really matter for classes (but then those aren't C ABI compatible anyway), but all exported functions will be fine.

      Or did you mean something else by this?

    21. Re:I don't get it... by jcdr · · Score: 1

      The frustration cam from things like this, not available in C++:
      int toto(int len) {
                      char buffer[len]; /* Doing something with the buffer */
      }

      The "extern C" statment is to use a C library from a C++ application, not to use a C++ library from a C application !

    22. Re:I don't get it... by jd · · Score: 3, Interesting

      I used Ada some time back. It's a nice object-based language (not OO, object-based) but its strictness could sometimes be infuriating. Good, but infuriating.

      I wouldn't want C to go in the direction of Ada - yes, the safety of C needs improving, but I regard C as being increasingly a universal starting point, a theoretical third-generation language rather than an actual one. There are now many dialects of C and many spin-off languages, some using that starting point better than others. It's a bit like the Cambrian Explosion, only the offshoots can still borrow from the central stem.

      Ada, however, is highly architectured, like Occam. Architectured languages are intended for very specific purposes and fulfill those purposes extremely well. Well, when they've been architectured correctly, that is. They've traded in the theoretical base point and the benefits of evolution for the benefits of being highly predictable and highly dependable within their niches. A well-written Ada program has levels of assurance on reliability that no C program could have -- or ever should have, because to have that level of assurance would kill off the very thing that makes C so powerful, which is the rate at which it evolves and de-standardizes. (Destandardization means you can exploit and assimilate new ideas faster. C is The Borg.)

      --
      It's a small world and it smells funny; I'd buy another if it wasn't for the money; Take back what I paid (SoM)
    23. Re:I don't get it... by shutdown+-p+now · · Score: 1

      The frustration cam from things like this, not available in C++:
      int toto(int len) {
                                      char buffer[len]; /* Doing something with the buffer */
      }

      It doesn't have the same exact feature, but std::vector will do everything a VLA can, and then some.

      (Yes, I know it's also an extra heap allocation. Unless you're writing for a DSP, it is highly unlikely that it will have any observable perf penalty.)

      The "extern C" statment is to use a C library from a C++ application, not to use a C++ library from a C application !

      It's both, actually. It has two effects: first, it makes C++ avoid using name mangling and produce linker names compatible with C, and second, it makes the functions use the C calling convention. So, if you want to write a library in C++ that is callable from C, you have to apply extern "C" to all exported symbols, otherwise there will be no way to refer to them from C due to name mangling, and even if you do get them (e.g. via dlsym), you won't be able to call them since they'll expect the first few arguments in registers.

    24. Re:I don't get it... by jd · · Score: 1

      Well, I'm not talking any specific implementation of C (those are all dialects and not pure C) but the specification itself. It is a third-generation language with no features taken from the first, second, fourth or fifth generations. It could be argued that it blurs the line between procedural and functional, but it takes nothing from stack languages, object languages or other classes. (AspectC uses aspect-oriented programming, but it's a C dialect again and not C.)

      In that sense, the specification is "pure" because it fits into a well-defined niche in the programming family tree, the same niche it has always inhabited and which it inherited from B and the B family of languages.

      Are any actual implementations pure? Hell no! They mash concepts from all over the place, plus novel ideas of their own. (In the case of Microsoft's C, I'd say the novels were pulp fiction.) It's no different from the standards of CORBA, SQL, etc - a baseline that's nice, neat and never used because you really need the extensions that nobody is ever going to cooperate on.

      If implementations were pure, you might still need tools like autogen/automake/autoconf or CMake, but those tools would be lighter and simpler and wouldn't need to spend 3/4s of the time just figuring out what the compiler and runtime library can do, they'd only need to bother with extensions and external libraries.

      --
      It's a small world and it smells funny; I'd buy another if it wasn't for the money; Take back what I paid (SoM)
    25. Re:I don't get it... by jgrahn · · Score: 1

      That line isn't going to get any less false the more you C++ zealots keep repeating it. If you have a modern C application that can compile as C++ with a few extra casts here and there, then you're really missing out on lots of useful new syntax and semantics in C, both standard and extended.

      Maybe so (especially since I don't know C extensions) but you're missing out on *more* useful C++ features.

      I know it may surprise you C++ guys, but full-time C programmers don't secretly wish they were using C++. It's been right in front of us the whole time, and frankly we thought the whole thing would blow over until Google started mass producing legions of C++ zombies who are intent on porting every open source application to C++.

      Never heard of that before. I use C++ because it's a good C-like language for plain old Unix programming, with a good, free compiler and access to all C libraries. I don't think I've ever met a Google-generated C++ zombie.

      Now its starting to get personal, because it's really hard to use C++ libraries in C, Perl, Python, Lua or basically anything other than C++, notwithstanding the mountains of wrappers, compiler options, and linker flags that allow access to a few useless entry points.

      Agree. Libraries should primarily have a C interface. I can wrap them myself in C++ if I want, and probably do a better job (from my project's point of view) than some library author.

    26. Re:I don't get it... by Anonymous Coward · · Score: 0

      Bah, humbug. C is a better OOP language than C++. At least you can do things right with it, albeit tediously.

      (in theory c++ lets you do that too but people will look you even funnier if you go re-implementing oop in a language that has superficially similar stuff on its own)

    27. Re:I don't get it... by Ungrounded+Lightning · · Score: 2

      Objective C, like Smalltalk, has an issue with construction and destruction: Overridden methods use the sub/derived version if called during the execution of the super/base class constructor. This means writing a sub/derived class has the potential to break the already-debugged super/base class constructruction, which must be rechecked for every sub/derived class.

      C++ gets this ALMOST exactly right: Base class constructors get the base class version, derived class constructors get the derived class version. Iterate down the entire hierarchy. Equivalently with DEstructors as the successive levels are torn down.

      I say ALMOST because the spec, and most compilers have what IMHO is a bug: During construction and destruction of member objects, if the member object constructor or destructor (or something it uses) gets hold of a pointer to the containing object and calls an overridden method it SHOULD get the base class version. (On construction the support for the derived class version is not initialized. On destruction it's already torn down.) But whether it actually gets the base or derived version is problematic.

      If you take the binary combination of what the constructor and destructor get there are three "wrong" and one "right" combinations. In the early days cfront and cfront-derived compilers got it "wrong" one way, three compilers for PCs got it "wrong" another way, and gcc got it "wrong" the third way. So if (as I asked them on each of the first two standards efforts) they had specified using the "right" behavior, everybody would have had to make a minor change and nobody would have had an advantage.

      The first ANSI standard explicitly left this undefined and the second said essentially "don't write code that lets this happen". B-b (I haven't really looked at the recent update to see what it says.)

      This was important to the project I was working on back then: We had rolled our own garbage-collection and exception-handling systems, using preprocessor-defined overridden virtual function bodies to track the level of construction. (Catch and throw were still just reserved words and the politically correct way to handle heap management was with user-written explicit allocation and deallocation.) With this "bug" we couldn't count on correctly handling an exception thrown or garbage-collection triggered by a member object constructor or destructor. So we couldn't use them. Instead of building compact composite heap-allocated objects we had to use smartpointers, separately heap-allocate the "contained" objects, and knit together a cluster of separate objects, Smalltalk-style. B-b

      --
      Bantam Dominique roosters crow a four-note song. Once you've heard it as "Happy BIRTHday" you can't NOT hear it that way
    28. Re:I don't get it... by Anonymous Coward · · Score: 0

      C++ does something similar, but in a less memory-expensive way: Instead of putting the function pointers to each function in the objects themselves, it recognices that for the same class, the pointers will always point to the same functions, and therefore they put all those functions into a separate structure, called virtual table, and only put the pointer to the virtual table into the struct. So for virtual functions, foo.bar() is internally (more or less) foo._vptr->bar(foo).

    29. Re:I don't get it... by Anonymous Coward · · Score: 0

      I say ALMOST because the spec, and most compilers have what IMHO is a bug: During construction and destruction of member objects, if the member object constructor or destructor (or something it uses) gets hold of a pointer to the containing object and calls an overridden method it SHOULD get the base class version. (On construction the support for the derived class version is not initialized. On destruction it's already torn down.) But whether it actually gets the base or derived version is problematic.

      Actually, at the time the members are constructed, the complete object they are member of doesn't yet exist, therefore you shouldn't call any member functions of it, period. However there's no way to reasonably model it in the type system without getting too restrictive (e.g. you want to be able to receive a pointer to the member object in the constructor in order to save it, and use it later in member functions called when the full object is already constructed.

    30. Re:I don't get it... by kasperd · · Score: 1

      You can basically take your existing C code and compile it with a C++ compiler in C++ mode, and with a very few exceptions it will compile and work just fine.

      I tried that a while ago. It doesn't even compile. I get this error message

      error: expected primary-expression before ‘.’ token

      I have no idea how to fix that error. The line which triggers it looks like struct s v={.p=0}; AFAIK there is no C++ equivalent for this.

      --

      Do you care about the security of your wireless mouse?
    31. Re:I don't get it... by thogard · · Score: 1

      Someone told me a bit of code wasn't too clean just the other day. After a mmap with a hard coded address and MAP_FIXED and loading a file, it does this:
      fn=0x972084;
      x = ((int (*)(int,int)) fn)(a,b);

      I guess Push A,B and a JSR 0x972084 might be cleaner.

    32. Re:I don't get it... by Raenex · · Score: 3, Informative

      It is a third-generation language with no features taken from the first, second, fourth or fifth generations.

      You're way overstating the case for C as some theoretically pure language. It's been tagged as a "high level assembler" for a reason, in that the underlying machine bleeds through (the second generation) much more than in other "third generation" languages.

      C is just a language that happened to take off. It isn't pure in any sense of the word. It's got half-assed "modules" based on crude file inclusion. Its mix of pointers, arrays, and integer types is baroque. It's got the beginnings of inheritance with its unions. It's structural but supports goto and setjmp/longjmp. This list is by no means exhaustive.

      It's also extremely dubious to say that object-oriented doesn't belong in the third generation of languages. Simula 67 was the first -- that's 1967, predating C. Also, Cobol, Lisp, and Fortran were third generation languages, all with distinct forms.

    33. Re:I don't get it... by jcdr · · Score: 1

      Yes, you can use VLA and disable name mangling...

      Still frustrating to have to use relatively non trivial constructs to do really simple basic things.

    34. Re:I don't get it... by LizardKing · · Score: 1

      The Foundation libraries started life at Stepstone, which was founded by Brad Cox. Cox invented Objective-C as a way to add Smalltalk like object oriented features to C, and he documented both the language and libraries in a subsequent book. When Steve Jobs set up NeXT, he recruited people who were familiar with Stepstone's work, which was then licensed it to form the basis of the NeXTstep development system (along with an excellent IDE and GUI builder).

    35. Re:I don't get it... by Anonymous Coward · · Score: 0

      except ... this is used ONLY if function calling "foo.bar()" does not know real type of foo at compile time (as in it could be one of several different class types) if foo class type is known at compile time than it is converted simply to "bar(foo)" (there is no de-referencing of foo, _vptr, and bar, simply pointer to function bar is directly used/embedded in calling function)

    36. Re:I don't get it... by jeremyp · · Score: 1

      Objective C, like Smalltalk, has an issue with construction and destruction: Overridden methods use the sub/derived version if called during the execution of the super/base class constructor.

      There's no such thing as construction / destruction in Objective-C. Allocation and initialisation are separate processes, although invariably done together.

      Anyway, although the problem you describe is there theoretically, it doesn't happen in practice. Initialisation tends to work with instance variables (Apple's guidelines recommend avoiding sending messages to self in initialisation). Also dynamic binding of methods makes inheritance much less common in Objective-C than the C++ alike languages.

      That's one theoretical issue with Objective-C. Another is that sending Objective-C messages is slower than calling C++ functions, even virtual ones. Compared to the horrible misdesigned "features" of C++ these are minor. The C++ designers have spent all their time adding more new features, resulting in a hugely bloated language with a syntax, that is too complex for a compiler instead of solving the basic problems like the fragile instance variable issue.

      --
      All I want is a secure system where it's easy to do anything I want. Is that too much to ask ~~ Randall Munroe
    37. Re:I don't get it... by Anonymous Coward · · Score: 0

      Um. Isn't that just a vendor specific opaque pointer and some provided functions?

      __m128* a, b; ...
      _mm_mult_ps(a,b)

      or so?

    38. Re:I don't get it... by fnj · · Score: 1

      I can well understand why you're posting as AC, but suppose you try to list the "lots of new syntax and semantics" in C that is NOT in C++.

    39. Re:I don't get it... by fnj · · Score: 1

      C++ compilers whines too much.

      I sympathize. C++ makes it harder in important and fundamental ways to be a lousy programmer.

    40. Re:I don't get it... by fnj · · Score: 1

      Thank you for a pertinent and specific comment.

      You are using a C99 designated initializer. I consider those very nice and their lack in C++ has been a sore point to me. Until NOW. Because the C and C++ WG's have a history of not being synchronized, that did not make it into C++ until the next following C++ standard, C++11. I am pleased to tell you that the just-released clang 3.1 now has this feature in C++ mode. It shouldn't be long until gcc has it. A quick summary of what I happen to think are the most important catch-up features, and some links to give more detail, is here.

      In future, there is a move to better synchronize the C and C++ WGs.

    41. Re:I don't get it... by Anonymous Coward · · Score: 0

      Why should I use a vector, and all the associated overhead, for an array that will never change size?

    42. Re:I don't get it... by shutdown+-p+now · · Score: 1

      Because you'd be writing in C++, which doesn't have VLAs. And because the overhead doesn't matter for most practical purposes.

      They're working on adding something like VLAs to C++ for the next standard, though as a "magic library" solution - a new class std::dynarray that cannot be resized and is otherwise defined such that the compiler may implement it as a true stack-allocated VLA. In the meantime, there's alloca for those extremely rare cases where the heap allocation really affects your perf.

    43. Re:I don't get it... by hazah · · Score: 1

      What does this do?

    44. Re:I don't get it... by Anonymous Coward · · Score: 0

      Named/designated initializers.
      Compound literals.
      Variable-length arrays (not using malloc/new), with run-time sizeof operator evaluation.
      restrict qualifier.
      Implicit void pointer conversions (casting hides bugs! although admittedly C++ code should never use malloc).
      Anonymous union/struct members.
      Flexible array members.
      enum-int equivalence (C compiler warnings about enum-int conversions are beginning to piss me off; they do it because of the crossover with C++).
      _Bool type (common in modern C).
      _Complex and _Imaginary types (not so common, optional in C11).
      Scope of nested tags.
      _Generic directive (brand new in C11 without any history, so very uncommon).
      And there are myriad corner cases about certain statement and expression semantics

    45. Re:I don't get it... by PCM2 · · Score: 1

      Google is mass-producing C++ zombies? Surely you mean Microsoft, at least...

      --
      Breakfast served all day!
    46. Re:I don't get it... by Anonymous Coward · · Score: 0

      C++11 DOES NOT have designated initializers. If you feel I'm in err, please provide chapter and verse of the standard. I do very little C++ programming, but I have a copy of the standard right in front of me and regularly browse it (I hesitate to say read because unlike the C standard, the C++ standard is written from the perspective of compiler writers instead of as a concise definition of an abstract machine).

    47. Re:I don't get it... by kasperd · · Score: 1

      The code creates a variable called v of type struct s, in which the field v is initialized with the value 0. There is a different syntax for such initializations in which you just list all the values for individual fields. The other syntax is supported in both C and C++, but it is less readable, and it has the drawback that changing the definition of the struct changes the semantics of the initialization.

      I could have written struct s v={0}; which would initialize the first field with value 0. If p was the first field, it would do the same. But now when you read the code, you won't know which field is being initialized. And if the struct is changed such that p is no longer first, the code will no longer do what it used to do.

      --

      Do you care about the security of your wireless mouse?
    48. Re:I don't get it... by kasperd · · Score: 1

      I am pleased to tell you that the just-released clang 3.1 now has this feature in C++ mode. It shouldn't be long until gcc has it.

      If that happens I will give my code another try with g++. Then it might become feasible for me to write code, which compiles with both C and C++.

      Another comment says this feature is not in any C++ standard. I don't know which is true.

      --

      Do you care about the security of your wireless mouse?
    49. Re:I don't get it... by Anonymous Coward · · Score: 0

      When it was just Microsoft, I didn't care. Those were the good old days, where C++ programmers on Linux were few and far between. Remember, one of the reasons Gtk/Gnome emerged was because C++ just wasn't that welcome in the FOSS community. People were comfortable and content with C.

      That slowly changed as Microsoft programmers became interested in Linux and FOSS, but it really exploded with Google. Google really prefers C++ (even making some of the old Bell Lab guys code in C++ when they'd prefer C), and Google is really involved in FOSS. And while I think Google does amazing stuff, I really dislike the influx of C++ programmers. It's sort of like Visual Basic programmers running amok, oblivious to the existing culture.

      And don't get me started on Google's style guide. Traditional style was hard tabs (as evidence by the entire BSD code base, old GNU software, as well as the Linux kernel), but Google requires spaces, and 4 at that. It's becoming a friggin' nightmare, this influx of Google kids upsetting the natural balance of things.

    50. Re:I don't get it... by fnj · · Score: 1

      C++11 DOES NOT have designated initializers.

      Good catch. C++11 as a standard does not have them, but clang 3.1 in C++ mode DOES have C99 designated initializers as an extension. "clang++ -std=c++11 -o try try.cpp" compiles them fine. Since I had made up my mind not to use C++ until it supported designated initializers, I decided clang 3.1 was my ticket.

      I think you'll find gcc also picking this up; in fact I'm not sure why 4.7 still does not allow it.

    51. Re:I don't get it... by fnj · · Score: 1

      Other comment is true actually, but see my further reply. I'm not sure it matters if they are in the standard yet, as long as they are picked up along with the rest of C99 as applicable, as blazingly obvious extensions by the compilers people actually use. After all, to the best of my knowledge neither gcc nor g++ never to this day fully implemented every part of C++98.

      Until gcc sees the light, and even after that day as a matter of fact, I recommend clang very highly.

    52. Re:I don't get it... by Anonymous Coward · · Score: 0

      GCC may never support it. Some brief Googling suggests that g++ developers are not keen on embracing every new C feature. It could happen in the future, but they have refused to do this for over 10 years, even though they support a very similar GCC-only syntax.

    53. Re:I don't get it... by cheesybagel · · Score: 1

      Well if you use SSE intrinsics you just lost one advantage of programming in C which is portability across different hardware architectures. OpenCL is supposed to help with that (e.g. float4, int4) but I see no reason why you shouldn't be able to do that in plain standard C. The fact is all instruction sets in common use today have vector instructions (SSE, NEON, AltiVec, VIS) and they can easily be emulated on scalar architectures... So why not add vector support?

  13. Missing features by Anonymous Coward · · Score: 1

    vector types:
    I don't mean c++ vectors, I mean opencl like vectors. float4, double2, etc... and vectorized versions of the standard math libraries sin, cos, etc... So you can do true cross compiler, cross platform, and cross cpu vector programming.

    closures:
    In corporate Clang blocks. They are just so useful.

    1. Re:Missing features by AuMatar · · Score: 5, Informative

      C runs on way too many devices without floating point support to add those as standard libraries. It wouldn't be useful on many platforms.

      And C isn't about adding every feature in the world. The language itself is pretty much done. They're just changing libraries. They'll never add a major feature like closures, nor should they. If you want them, use another language when they're designed in well, not hacked on.

      --
      I still have more fans than freaks. WTF is wrong with you people?
    2. Re:Missing features by shutdown+-p+now · · Score: 2

      C runs on way too many devices without floating point support to add those as standard libraries. It wouldn't be useful on many platforms.

      Well, it already has all common math operations on floating point numbers as part of the standard language/library. Quite obviously, any vector operation can be implemented as a simple loop over the elements invoking the corresponding (already standard) scalar operation. Making them better optimized would then be a quality of implementation issue. Making this standard would mean that people could write portable code that works faster on compilers with special support for it, but still works correctly (and no slower than corresponding code with explicit loops) everywhere else.

      It doesn't even require any new language features, just libraries. Just add float4 etc as structs, and define standard library functions for all operations including arithmetic. Let compilers implement them as intrinsics where that makes sense.

      Maybe it doesn't make sense as part of the core standard, but it would make for a good TR.

    3. Re:Missing features by tepples · · Score: 2

      Quite obviously, any vector operation can be implemented as a simple loop over the elements invoking the corresponding (already standard) scalar operation. Making them better optimized would then be a quality of implementation issue. Making this standard would mean that people could write portable code that works faster on compilers with special support for it, but still works correctly (and no slower than corresponding code with explicit loops) everywhere else.

      I believe the idea was that restrict pointers would help the compiler discover where it can transform existing code to use vectors.

    4. Re:Missing features by Anonymous Coward · · Score: 0

      C runs on way too many devices without floating point support to add those as standard libraries.

      Then how is it that C can support float, double, complex float and complex double (along with the associated standard libraries), if it runs on "way too many devices without floating point". I don't see why it's such a big deal to add vector types.

      On platforms without vector instructions, the compiler fails back to scaler versions, then on platforms without floating point, the scaler floating point is then emulated using integer instructions. Or you just don't use that feature if your platform doesn't support it. There is no reason to hamstring the language because of that.

    5. Re:Missing features by shutdown+-p+now · · Score: 3, Informative

      Restrict is to help the compiler discover when it can assume the lack of aliasing, and therefore aggressively prefetch and cache values. This is especially so when combined with static size array arguments (as in int[static 4]), which by definition cannot be null, permitting compiler to fetch without any checks. I guess it can also be used to improve parallelization by letting the compiler assume lack of dependencies between reads and writes where otherwise it would have to assume they exist, but that's not quite the same as vectorization.

      I know some compilers can do auto-vectorization on loops over arrays - notably Intel - but this is still too limited to be portable. Most implementations require you to use the (implementation-defined) intrinsics to do the same, which to me strongly indicates that this is the way this should be standardized. Also, writing such loops explicitly every time is unnecessarily verbose.

    6. Re:Missing features by Anonymous Coward · · Score: 0

      It wouldn't be useful on many platforms.

      Only useful on x86, arm, ppc, sparc... but who uses those?

    7. Re:Missing features by Anonymous Coward · · Score: 0

      If you want them, use another language when they're designed in well

      I do I use them in C in Clang where they are designed well.

    8. Re:Missing features by Anonymous Coward · · Score: 0

      check out liboil. it doesn't need to be standard

    9. Re:Missing features by shutdown+-p+now · · Score: 1

      Their main website and wiki seem to be down, all it has is the download itself. Does it work with MSVC on Win32?

    10. Re:Missing features by serviscope_minor · · Score: 3, Interesting

      gcc is pretty good at vectorisation, provided it can prove a lack of aliasing (which is very, very hard).

      If you make heavy use of statically sized C-style arrays allocated on the stack, proving a lack of aliasing is much easier, and gcc generates vectorised code pretty well.

      What gcc can't do is specially tag pointers allocated from malloc() as somehow similar to stack allocated arrays and assume that they don't alias in the same way. I think thbe intel compiler is much better at that, which is where many of the gains come from.

      GCC is getting better however. In some cases it can prove that malloc()/free() pairs haven't achieved anything and elides them entirely. However the functionality seems pretty new and incomplete and ti doesn't work with new/delete yet.

      --
      SJW n. One who posts facts.
  14. Re:A certain well-known coder will dump all over t by Anonymous Coward · · Score: 0

    0... and... ...[crickets chirping]

  15. Re: by hawguy · · Score: 4, Insightful

    The multi-threaded stuff sounds nice. But bounds checking, really? How difficult is it to check buffer size before copying?

    Given the number of buffer overflow bugs that are found in C programs, apparently it's fairly difficult to do it consistently and correctly.

  16. Who needs threads? by spaceyhackerlady · · Score: 3, Insightful

    I've never been a fan of putting multi-threading/multi-tasking in a programming language. You get one abstraction of threads/tasks, and that's it. If you want to do it differently, you have to do it yourself with library calls. So why not leave it that way and keep the language simple?

    Unless there is an awfully good reason not to (and I haven't encountered one yet), I use pthreads.

    ...laura

    1. Re:Who needs threads? by Monkey-Man2000 · · Score: 1

      I've never been a fan of putting multi-threading/multi-tasking in a programming language.

      This is probably to promote and facilitate the use of C on multi-core machines, but I haven't RTFA.

      --
      This post was generated by a Cadre of Uber Monkeys for Monkey-Man2000 (603495).
    2. Re:Who needs threads? by Anonymous Coward · · Score: 0

      Consistency checking, probably. The article mentions a new atomic type qualifier and a thread local storage class.

    3. Re:Who needs threads? by moogla · · Score: 2

      They standardized the naming convention of thread primitives for C11-compliant compilers and C-libraries. The system can still use posix threads under the hood, but now there is a intended to be forward compatible that you can leverage.

      You will still be able to use one or the other. In some implementations you may be able to leverage both facilities (like using _Thread_local storage qualifiers in code that otherwise uses posix threads).

      --
      Black holes are where the Matrix raised SIGFPE
    4. Re:Who needs threads? by Jerslan · · Score: 2

      Yeah, but you really should try to code for a single standard... Mixing them because one or even most implementations support it is bad juju IMHO.

      GCC and Clang/LLVM may support using _Thread_local with a pthread, but some other compiler you may need to use (for some strange reason) might not and then you would need to do a lot of work to get things going with that compiler.

      It's a pet peeve of mine when I see a lot of mixed standards... If you're going to use pthread, use pthread. Don't try to mix it with something else just because you think you can (or your compiler lets you). Even if the new threads.h is just an abstraction layer on top of pthreads, it's best to stick to the threads.h method calls if you go that route. Mixing calls can sometimes lead to unexpected results.

    5. Re:Who needs threads? by Mr+Thinly+Sliced · · Score: 5, Informative

      IIRC it's because without putting explicit constraints on the memory model (needed for threading), you end up with holes of varying sizes when talking to memory from threads.

      It's mostly to do with CPU caching / memory barriers and having a consistent temporal view of data in and out.

      If it's not in the language, you end up with each platform/compiler having their own approach to barriers / atomics which makes glueing different bits of code together with different approaches a crap shoot when it comes to consistency.

      Here's a good place to start

    6. Re:Who needs threads? by Anonymous Coward · · Score: 1

      Yep. Whenever I've been forced to deal with threads, I find myself converging on message passing. If I don't, it just gets too insane. I understand this is something that Erlang nailed. I've never coded in it. It's my understanding that it basicly does what I end up doing and says, "to hell with threads, let's just pass messages back and forth amongst process objects". When I'm doing this in C, I end up with pthreads, structs for each thread, and a messages center that's briefly locked so they can talk. Oh for the love of God, the rats nests of race conditions you can get if you actually try to maintain a bunch of thread setups with different purposes...

    7. Re:Who needs threads? by antifoidulus · · Score: 1

      Awesome info, very unfortunate choice of domain name.... :P

    8. Re:Who needs threads? by jcdr · · Score: 1

      "A Computer is a state machine. Threads are for people who can't program state machines." -- Alan Cox

      http://en.wikiquote.org/wiki/Alan_Cox

    9. Re:Who needs threads? by Anonymous Coward · · Score: 0

      Also: "However, all of the popular C threading libraries have thus far been non-standard extensions, and hence non-portable."
      never heard of OpenMP obviously which is well-standartised and supported by many compilers...

    10. Re:Who needs threads? by dargaud · · Score: 1

      I've never been a fan of putting multi-threading/multi-tasking in a programming language.

      Well, that's the one thing I truly miss in C. I've used Ada where the multithreading model is part of the language, is brilliantly clear, a joy to use and SAFE. In C, using either posix threads of MS threads it's a nightmare and I've had to scrap entire programs because the logic of the program simply wouldn't work with this mess of threads, semaphores and whatnot.

      --
      Non-Linux Penguins ?
    11. Re:Who needs threads? by Mr+Thinly+Sliced · · Score: 1

      While I have the utmost respect for Alan this quote is unfortunate.

      The "new world" is coming and it's massively multi-core. Now we can call it multi-process or call it multi-thread - we still need a consistent approach to parallel execution that guarantees consistency.

      In the case of multi-process, using shared memory means we need a consistent memory model in exactly the same way as multi-threads (think two processes trying to update independantly two 8 bit values next to each other).

    12. Re:Who needs threads? by Anonymous Coward · · Score: 0

      The quote is easy to take out of context in which it is about switching context, instead of avoiding divide-and-conquer on the said state machine. ;)

    13. Re:Who needs threads? by Anonymous Coward · · Score: 0

      actually i do agree, with exception of multi-cores, i like one thread/core model

    14. Re:Who needs threads? by fatphil · · Score: 1

      He seems to be ignoring the fact that it's possible for two parts of a modern computer to be doing different things at the same time, and without synchronisation. With an attitude like that, it's surprising he doesn't bin interrupts and DMA too.

      Perhaps he prefers full task separation, but in that case he ought to make his bloody IPC more efficient!

      (And yes, the swearing is in jest, I've worked as a linux kernel developer on the same project as Alan in the past.)

      --
      Also FatPhil on SoylentNews, id 863
    15. Re:Who needs threads? by jcdr · · Score: 1

      Yes, this was a bit provoking. But as the same time, it's true that state machine is extremely fundamental to computers while a lot of code are not well organised around a clean state machine. It's not uncommon to see programmers that like to add a thread instead of fixing the design of the state machine.

    16. Re:Who needs threads? by themusicgod1 · · Score: 1

      How many states does the cloud have?

      --
      GENERATION 26: The first time you see this, copy it into your sig on any forum and add 1 to the generation.
    17. Re:Who needs threads? by fatphil · · Score: 1

      If your state machine is the direct product of N simpler state machines, then in fact you've got a system with N independent states, and it is *best* modelled with N separate threads. OK, an exact direct product is unusual, but often it's not far from the truth. One of the biggest flaws I see in less experienced developers' code, is their inability to factor and simplify, and you then end up with one monster state machine of high complexity, and high defect count. So Cox was accidentally encouraging messy and flawed designs.

      --
      Also FatPhil on SoylentNews, id 863
    18. Re:Who needs threads? by jcdr · · Score: 1

      I don't agree: sub state machine don't have to be in separate threads.Forget the theoretical illusion that "independent states" exists: in a way on is an other, sub state machines have to communicate in some way. Most of the times the sub state machines are organized into a hierarchy to compose the main state machine. In reality you have to distribute events across the hierarchy depending of state that the OS is not award of, so threads do no help. Or some sub state machines have to change depending of the state of the others, raising synchronization issues when using threads. So many, many, many nasty and difficult to reproduce bugs cam from timing issues that affect threads coherency.

      Yes monster state machine is not good, but this is exactly what Alan wanted to say: if you are unable to design a good state machine (or actually a hierarchy of sub state machines) then threads will not save you but make the whole mess even worse. After 25 years of programming, I so often fix so many broken design by killing thread and replacing them by a nice hierarchy of state machines and a lot of debug. All the synchronization problem magically disappear, the code is more easy to read, use less resources, more easy to trace, and more easy to verify on a test bench.

      I also do a lot of electronics and it's so obvious when you do digital hardware that synchronous state machine is the only base that permit to construct everything reliable. Every time you lost synchronization, you get a problem that need a additional circuit to keep is safe. Thread is a way to lost synchronization. Don't use them for anything other than for performance augmentation.

    19. Re:Who needs threads? by fatphil · · Score: 1

      "Or some sub state machines have to change depending of the state of the others"

      Then the whole state machine is not anything like a direct product of two smaller state machines. I'm not talking 'sub-state-machines' I'm talking complete orthogonality.

      "I so often fix so many broken design by killing thread and replacing them by a nice hierarchy of state machines and a lot of debug. All the synchronization problem magically disappear"

      Understandable, synchronisation is hard to get right. And if you can't do it right, you definitely should be using multiple threads. I have some true horror stories on this topic, regarding a large chipset vendor and their kernel, but alas I'm under NDA.

      --
      Also FatPhil on SoylentNews, id 863
    20. Re:Who needs threads? by jcdr · · Score: 1

      Completely orthogonal state machine don't have to communicate, so you should use an other process, not an other thread.

      Synchronization is a desirable feature between state machines that have to communicate. Using thread make the synchronization more difficult, less predictable, and harder to verify. Now there is situation when you wants threads to fix performance, like shorter latency or multiple core distribution. But this will invariably make the system more complex, not less.

      Using threads don't solve any synchronization problem ! At the best is just move it in an other place. I have also observed that more a code is secret, more likely it tend to abuse of threads.

  17. multithreading is too little, too late by Anonymous Coward · · Score: 1

    multithreading support was desperately needed 15+ years ago. But now low-level multithreading model doesn't scale, and we actually need more distributed parallel processing features. Extension libraries, such as posix, can fill in support for multithreading for those rare cases where it is worthwhile. (where you need concurrency, but not a lot of concurrency)

    bounds checking on the otherhand lets a programmer take advantage of information the compiler often already has available. Although I would argue that simple bound checking is too small, and would like for a full set of formal verification extensions standardized for C.

    1. Re:multithreading is too little, too late by tyrione · · Score: 2

      I suppose you're not into OpenCL, right?

  18. Adds Rock music support by PaddyM · · Score: 2

    cause this language goes to 11
    *puts on sunglasses*

  19. Re: by shutdown+-p+now · · Score: 1

    It's not difficult at all, but people forget about doing it all the time. The point of those new interfaces is really more about forcing you to do that check (the function will do it, but you have to provide the size of the buffer to it).

  20. Re: by JustNiz · · Score: 1

    Why do you need to explicitly check the buffer size at all?
    A well-designed program ensures you can't crash the buffer to start with.

  21. Re: by bleedingsamurai · · Score: 1

    I blame the programmers not the language.

    I don't even have to think about doing it. Often times it is as simple as an additional if statement to check the size of your source and destination buffers. If the destination buffer is smaller, just don't do the copy.

  22. Header files dependency by Anonymous Coward · · Score: 0

    What about solving header [hell] dependency in the new C standards ?

  23. Re: by bleedingsamurai · · Score: 2, Insightful

    Are you suggesting it is possible to create a program that doesn't involve buffers?
    Even the simplest Hello World program uses buffers. Even fancy languages that have run-times and virtual machines use buffers. Buffers are an integral part of designing software because they are an integral part of how the machine works at the hardware level.

  24. Re: by turbidostato · · Score: 4, Insightful

    "I blame the programmers not the language."

    Good! Now you have to change the language once or blame the programmers forever (since you shouldn't expect to change them anytime soon).

  25. Re: by Anonymous Coward · · Score: 0

    Where did he say it is possible to create a program that doesn't involve buffers? Way to deliberately misinterpret what he is saying.

    What he is saying is that given the right language, buffer handling is done for you, drastically decreasing the numerous security flaws attributable to wrong buffer sizes, which is fairly common in C. Stop being obtuse in an attempt to be a pedantic troll.

  26. Bullshit by Tough+Love · · Score: 3, Insightful

    Where did C99 go awry? Some of its mandatory features proved difficult to implement in some platforms. Other C99 features were considered questionable or experimental, to such an extent that certain vendors even advised C programmers to replace C with C++.

    Speak for yourself Microsoft. It is not our fault that you can't implement C99 features properly or on time. For the rest of us C99 is alive, well and popular. Just avoid Microsoft's shoddy compiler and you will be fine. Both GCC and LLVM do the job properly.

    By the way, similar comments apply to Microsoft's tardy and dodgy implementation of C++11.

    --
    When all you have is a hammer, every problem starts to look like a thumb.
  27. Re: by bleedingsamurai · · Score: 0

    If it is such a problem, go use another language. One that does all the thinking for you.

  28. Re: by turbidostato · · Score: 1

    "If it is such a problem, go use another language."

    But he was blaming *other* programers. You don't deal with this by *you* changing to another language.

  29. Multithreaded support by slasho81 · · Score: 1

    Nothing says irrelevant standard like having standardized multithreading support on year 2011.

  30. Re: by JustNiz · · Score: 2

    I'm not sure how you think printf"(hello world\n"); uses any dynamic (i.e. user-created/maintained )memory but never mind thats not my point here.

    What I am saying is that you write your code such that once you created a buffer, your program knows its length and is written in such a way that it isn't possible to crash it.

    For example, only use bounded functions like strncpy() rather than unbounded ones like strcpy().

  31. Re: by Anonymous Coward · · Score: 0

    I do use a different language. Why don't you tell all those people using C to switch to a different language?

    Given your responses I wonder if you really can think well enough to use C safely (and do so consistently).

    If it's so simple to check the bounds size before copying, why not have the language+compiler do it by default when necessary? Because you like to type extra lines?

  32. Re: by JustNiz · · Score: 1

    I'm not saying that at all. All potential buffer overflows are just a result of sloppy coding.

    Even in languages with no built-in protection like C you can easily and elegantly architect your code such that crashing buffers is impossible.

    People need to stop expecting languages to make up for their own lack of skill and/or attention to detail.

  33. Re: by viperidaenz · · Score: 1

    That's a great way to hide bugs, not fix them. If the inputs are not as expected then the result should be failure, not nothing. hence the concept of exceptions and exception handling.

  34. I'd like an updated K&R please! by Zaiff+Urgulbunger · · Score: 1

    I'd like an updated "The C programming language", although not necessarily by K and almost certainly not R! 'cos otherwise, I'll wind up buying some other book and I'll hate it because it's not as nice as K&R. And then I'll be all cross. :(

  35. Re: by bleedingsamurai · · Score: 1

    Some how you went from "buffer" to "dynamically allocated memory" which although related is not one and the same. I'm sure you can figure out how too look up the definitions of both and see that there is a difference.

    I'll admit I misinterpreted what you wrote.

    But here is the problem with strncpy() and similar functions it only reads so many characters. So if you are in a situation where more is being written into a buffer then is there;
    1) your string isn't actually a string because it isn't null-terminated.
    2) it is actually more work for you to implement the handling of the error, I can't think of too many situations where not having the whole string is useful. By explicitly checking buffer size, I can adjust my destination buffer to include enough space for the whole string and not loose any data OR if it is such a hideous problem I can simply exit() or return right then and there in fewer lines of code that are easier to read. At which point why even bother using strncpy() if I'm already checking buffer size manually?

  36. Re: by bleedingsamurai · · Score: 1

    Once again, only another statement, a call to exit() or return once the if statement decides your destination buffer is too small. We have a grand total of two additional statements.

  37. Re: by viperidaenz · · Score: 1

    Only two additional, mundane statements every time you access an array. Excellent!

  38. Really who does this crap by tralfaz2001 · · Score: 1

    Replace gets() with gets_s()! You couldn't call it something sane like get_line(), or even gets_line() to avoid name collisions. Anything connected with C++ just seems to spread its taint.

    1. Re:Really who does this crap by spitzak · · Score: 2

      Oddly enough all the _s crap seems to be driven by Microsoft. They proposed them, then modified their compiler to complain if you did not use them and instead used strcpy, etc. This includes functions such as snprintf which are *identical* to the _s versions, and a "safe" version of fopen that only checks if the FILE* argument is non-null (WtF?). For some reason no WIN32 api that could overflow buffers got a "_s" version and there was no warning for using them! The purpose appeared to be to piss off programmers and perhaps to discourage writing of portable software (though the warning was easily turned off).

      As you point out, there have been a million replacements for gets. The original K&R book had getline() which took the buffer length and was safe. All of them had more intelligent names and more useful behavior on overflow than gets_s.

      For strings there has been strlcpy and strlcat for years. Though the refusal to adopt these show the Glib maintainers have equaled Microsoft in their ability to be asses.

  39. C99 not a success? by tyrione · · Score: 1

    Here are two successful examples: Clang and OpenCL.

  40. R no more by John+Bokma · · Score: 1

    Sadly, R passed away October 12, 2011: http://en.wikipedia.org/wiki/Dennis_Ritchie

    1. Re:R no more by Anonymous Coward · · Score: 0

      I'm going to guess that's why he said "and almost certainly not R!"

    2. Re:R no more by Anonymous Coward · · Score: 0

      Glad someone else noticed. The rest of the world was too busy soiling itself over the death of that other guy

  41. Mod up! by naasking · · Score: 1

    Give this man some points! He has it exactly right.

  42. OOP sucks by Weezul · · Score: 2, Informative

    What features do you want?

    Automatic memory management? Isn't this what makes C++ so fucking insanely complex? Bad idea.

    Overloading? Umm, that's extremely dangerous in subtle complex code like operating system schedulers, computational code, etc. Very bad idea.

    Inheritance? Nah. Almost as bad as overloading, but also useless for most most activities.

    Templates? No, they're even worse than overloading. I suppose Java interfaces or Haskell typeclass could provide a safe form of overloading. I certainly acknowledge the desire to parameterize a struct on another type, but that's extremely complex for a low level language.

    Lambda expressions, ala C++0x? Interesting proposal, not exactly sure how the memory management works out, but perhaps one could grant the compiler the ability to build closures in this way, but subject to the programer's memory management.

    Yes, I'll grant that lambda expressions make sense, but not C++0x's lambda expressions, since they impose a memory management scheme. In essence, lambda expressions in C should be just-in-time optimizations that the programer controls manually.

    In truth, most object oriented language 'features' are actually bad design choices, well unless your doing GUI work where the error object oriented programming creates aren't catastrophic.

    Yes, there are vaguely functional features like parametric polymorphism and lambda expressions that might aid low-level programming, but they're complex enough to require a proof-of-concept language first. C must avoid the mad dash into standardization that created C++'s complexity.

    --
    The Christian religion has been and still is the principal enemy of moral progress in the world. -- Bertrand Russell
    1. Re:OOP sucks by jgrahn · · Score: 2

      What features do you want?

      Automatic memory management? Isn't this what makes C++ so fucking insanely complex?

      No. Have you ever used C++?

    2. Re:OOP sucks by serviscope_minor · · Score: 3, Informative

      Automatic memory management? Isn't this what makes C++ so fucking insanely complex? Bad idea.

      You're doing it wrong, frankly.

      If your programs are full of new/deletes in mismatched pairs, then you're missing out on much of the point of C++.

      Overloading? Umm, that's extremely dangerous in subtle complex code like operating system schedulers, computational code, etc. Very bad idea.

      WTF? I write computational code for a living. Good numerics libraries full of operator overloading make my code much, much more simple, reliable and correct. So, I'll stick with overloading thankyouverymuch.

      Inheritance? Nah. Almost as bad as overloading, but also useless for most most activities.

      I've honestly no idea what you're talking about. Classic OOP inmheritance has its uses, and it's used throughout the Linux kernel for instance (see e.g. vtables). C++ just adds compiler support. Other inheritance is just aggregation of data which is an entirely reasonable thing to do.

        Templates? No, they're even worse than overloading. I suppose Java interfaces or Haskell typeclass could provide a safe form of overloading. I certainly acknowledge the desire to parameterize a struct on another type, but that's extremely complex for a low level language.

      Templates are what makes sane numerics libraries great, and container libraries. In fact you've just admitted that they're useful, but for some reason, you don't want expressivity in your low level language. Also, C++ allows parameterization on an int, as well as a type, which is an especially powerful featureand is missing from almost all other generics systems.

      Lambda expressions, ala C++0x? Interesting proposal, not exactly sure how the memory management works out, but perhaps one could grant the compiler the ability to build closures in this way, but subject to the programer's memory management.

      You tell the compiler whether you want the closure to capture by reference or by making a copy of the data. In the former case, the memory in managed in exactly the same way as normal (via destructors) in the referenced variables. In the latter case, the lambda justs acts like a class with a bunch of data members and calls the destructors when it goes out of scope.

      Yes, I'll grant that lambda expressions make sense, but not C++0x's lambda expressions, since they impose a memory management scheme. In essence, lambda expressions in C should be just-in-time optimizations that the programer controls manually.

      I don't think you understnd lambdas. A lambda is a shorthand for making a struct with a bunch of data members and an overloaded operator(). That is all. It interacts with the language in exactly the same way as all other structs.

      In truth, most object oriented language 'features' are actually bad design choices, well unless your doing GUI work where the error object oriented programming creates aren't catastrophic.

      Now we have a kernel of truth which doesn't apply to C++. Yes, OO concepts are somewhat limited in scope. They are useful for some things, but not for others. People have widely abused them to apply to everything either by choice or because languages often provide few other mechanisms. C++ does provide those other mechanisms and doesn't force you to make make everything a massive ovject heirachy.

      Apart from in a small number of libraries I use, I make very little use of classic OO concepts like polymorphism etc. I use classes and methods, but as an encapsulation and occasionally aggregation mechanism. That's a far cry from classic OO, though.

      Yes, there are vaguely functional features like parametric polymorphism and lambda expressions that might aid low-level programming, but they're complex enough to require a proof-of-concept language first. C must avoid the mad dash into standardization that created C++'s complexity.

      lolwut? C++ a mad dash in t standardisation? Good troll, sir.

      --
      SJW n. One who posts facts.
    3. Re:OOP sucks by LizardKing · · Score: 1

      Ever looked at the smart pointer implementations in C++? Ever read the "Effective C++" or "Exceptional C++" books? I have, and they left me convinced that C++ is irredeemably brain damaged.

    4. Re:OOP sucks by petermgreen · · Score: 1

      C++'s complexity comes from the way it's designed. Rather than giging you things like smart pointers, strings etc as language builttins they give you the tools to build them yourself then build them in the standard libraries. Those tools are undoubtablly complex but most of the time application programmers don't need to worry about them. They can just use the smart pointers, strings etc that the libraries have built for them.

      It really doesn't make much difference to an application programmer whether smart pointers are implemented as a library using complex language features or as a language feature in their own right.

      What I really don't like about C++ is it's lack of a proper unit system which allows the compiler to avoid compiling the same shit loads of times and which allows the compiler to automatically work out what needs to be rebuilt. Yeah there are precompiled headers and tools like depcomp (from automake) which try to solve this but it's obvious they are hacks to make up for the lack of something that is a language feature in other languages (such as borland sytle pascal).

      --
      note: i'm known as plugwash most places but i screwd up registering that here somehow in the past and now can't register
    5. Re:OOP sucks by fatphil · · Score: 1

      No - don't worry about pointers! We can fix that by introducing auto_ptr! (C++98)
      Oh, shit, auto_ptr is bollocks, let's remove it again (C++11)

      Quite why anyone trusts these pollyannas with a programming language, I don't know. They'd be better suited to the fashion or pop music industry.

      I just hope one of the ringleaders of fucking up C++, Andrei Alexandrescu, doesn't fuck up Digital Mars' D project to the same extent as he fucked up C++ - that used to be a good language.

      --
      Also FatPhil on SoylentNews, id 863
    6. Re:OOP sucks by Yunzil · · Score: 1

      Good numerics libraries full of operator overloading make my code much, much more simple, reliable and correct.

      Sorry, but no. Operator overloading is the tool of the devil. If I see A + B in C, I know it's adding two numbers. If I see A + B in C++... well, there's no way to tell what's really happening.

      Templates are what makes sane numerics libraries great

      The only thing worse than operator overloading in C++ are templates in C++.

    7. Re:OOP sucks by badkarmadayaccount · · Score: 1

      Get an IDE gramps, class tooltips come free these days.

      --
      I know tobacco is bad for you, so I smoke weed with crack.
  43. internationalization and localization by PepsiMax · · Score: 1

    What is missing from the new standard is internationalization and localization.

    1. Re:internationalization and localization by Alex+Belits · · Score: 1

      This has nothing to do with the language. It's bad enough that Unix C library is included in there.

      --
      Contrary to the popular belief, there indeed is no God.
  44. Why? by Anonymous Coward · · Score: 0

    Don't we already have many bloated languages out there?
    The things they are adding should not be part of the language, but libraries.
    The language itself should remain small, simple and elegant.

  45. Y2K bug in the name??? by Anonymous Coward · · Score: 0

    Who would think that "11" is higher than "99".

    Could this be the last Y2K bug? Or is it one of those "Y2K features?"

  46. A question by Anonymous Coward · · Score: 0

    I have a question about these different C standards.
    Where am I supposed to learn how to use them?

    I learned C from the K&R book mostly, however I also know that some version of C allows mixed variable declarations and various other features.
    But I never really ``learned'' about these features.
    So how are you supposed to learn about newer features other than some blogger saying there is some new feature.
    If I go to the wikipedia page for C there is just some links to the ISO C working group and various standards.

    1. Re:A question by hazah · · Score: 1

      Learn what you will use.

  47. Re: by Lisias · · Score: 1

    Statements that that other languages do for you, even when you know this is not necessary making, oh tragedy, your programs to run slower.

    If I sanitize my inputs on the interfacing function, all the other called functions don't have to do it again!

    C is used to be used on memory/performance critical missions. Adding this bloat checking automatically will impact these missions.

    --
    Lisias@Earth.SolarSystem.OrionArm.MilkyWay.Local.Virgo.Universe.org
  48. OpenCL by Anonymous Coward · · Score: 0

    I'm more of a CUDA man.

    OpenMP is more applicable to this discussion, but the new C11's threads.h doesn't have anything like OpenMP's "#pragma omp parallel for". If it did, then I wouldn't have brought up C11's old fashion concurrency model.

    If you haven't tried OpenMP, I recommend you play it it. it will open your eyes to what can be done with a bit of C code. It's not as sophisticated as OpenCL/CUDA type solutions, but it does offer fine grain control over concurrency without bogging the programmer down in individual thread management.

    1. Re:OpenCL by Anonymous Coward · · Score: 0

      I'm more of a CUDA man.

      OpenMP is more applicable to this discussion, but the new C11's threads.h doesn't have anything like OpenMP's "#pragma omp parallel for". If it did, then I wouldn't have brought up C11's old fashion concurrency model.

      If you haven't tried OpenMP, I recommend you play it it. it will open your eyes to what can be done with a bit of C code. It's not as sophisticated as OpenCL/CUDA type solutions, but it does offer fine grain control over concurrency without bogging the programmer down in individual thread management.

      OpenMP sucks. libdispatch is better and produces faster code.

    2. Re:OpenCL by Anonymous Coward · · Score: 0

      OpenMP is also supported by every compiler that matters (i.e. GCC and VS C++ compiler).

  49. Re: by viperidaenz · · Score: 1

    Isn't that's what compiler optimisation is for - removing code that has no effect?

  50. Re: by samkass · · Score: 1

    The multi-threaded stuff sounds nice. But bounds checking, really? How difficult is it to check buffer size before copying?

    A little bit more difficult than not having to do it. And if you make writing secure code a little easier, it's a little more likely to happen.

    --
    E pluribus unum
  51. Re: by phantomfive · · Score: 1

    If you don't have to think of it, then I'll bet I could audit your code and find you've made mistakes.

    I've been programming C a long time, but I always double-check my buffers. Even if you do it perfectly, using a function that checks for you can save a line of typing. Not a bad thing.

    --
    "First they came for the slanderers and i said nothing."
  52. Re: by Jorl17 · · Score: 1

    Because, sometimes, you want to get out of bounds! Seriously, though, it's because it's not that simple, maintaining the good o'l efficiency.

    --
    Have you heard about SoylentNews?
  53. Hey, it is NOT new C Language, it is new C++ , by Anonymous Coward · · Score: 0

    Did you read the site ?

    It is "C++11" , not "C11"

    Do you guys mix the C standard with C++ ??

    1. Re:Hey, it is NOT new C Language, it is new C++ , by Anonymous Coward · · Score: 0

      You really should learn to read ...

      First link is about last year post on C++11

      Second link is about, I quote : "C11: A New C Standard Aiming at Safer Programming"

      Mod parent clueless

  54. Re: by Anonymous Coward · · Score: 0

    It's not about blame. It's about shutting down these exploits once and for all and making software safer. In case you haven't noticed, it's a hackers paradise out there.

  55. What about allowing a '&int' as a declaration by Richard_J_N · · Score: 1

    It's always annoyed me that to declare a pointer to int, we write:
            int *x;
    which means "let x be that thing which, when de-referenced, is an integer" or more briefly "(*x) is an int".
    [Anyone who thinks that it is really "int* x" (note the spacing) should consider what happens with "int* x,y" ]

    So, let's have an explicit pointer declaration. I propose:
        "&int x"
    meaning "x is a variable of type address-of-integer".

  56. Re:What about allowing a '&int' as a declarati by Alex+Belits · · Score: 1

    How about not?

    --
    Contrary to the popular belief, there indeed is no God.
  57. Bah, Humbug! by RKBA · · Score: 3, Funny

    Anything but the pure C as defined in the sacred Whitebook pollutes the simple beauty of C and obscures the language's clarity and its similarity to the instruction sets of most common CPUs.

    1. Re:Bah, Humbug! by Anonymous Coward · · Score: 0

      Anything but the pure C as defined in the sacred Whitebook pollutes the simple beauty of C and obscures the language's clarity and its similarity to the instruction sets of most common CPUs.

      ANSI heretic! Everyone knows the Second Edition is the spawn of evil! Only the pure, unadulerated First Edition for me, thanks.

  58. C+++ by SpaceLifeForm · · Score: 1

    Then you can run cXXX. Oh wait, some new tld owner would sue.

    --
    You are being MICROattacked, from various angles, in a SOFT manner.
  59. Re: by Anonymous Coward · · Score: 1

    Isn't that's what compiler optimisation is for - removing code that has no effect?

    The problem here is that the code has effect and isn't removed.
    ALso, no bounds checking in the world is going to help you unless you write the code to handle what you should do when you are out of bounds. Bounds checking only goes as far as crashing you program earlier or hiding the problem. You still have to consider that it might happen and write the code necessary to handle it.

  60. Re: by tbird81 · · Score: 1

    I write Hello World programs for a living. Here's some of my recent work:
    char buffer[10];
    sprintf(buffer,"Hello World");

      They use buffers, but because they're well designed they never cSegment violation Address 0x401a35

  61. Still needed: integral support for SIMD by JDG1980 · · Score: 1

    At its core, C is designed to be a sort of portable assembly language. Most of its original features were intended to map directly to PDP-11 opcodes, and fortunately these proved to be generic enough that they could be implemented much the same way on other systems. (You'd be hard-pressed to find an architecture where the C construct ++var; didn't map to an increment opcode.) This is what makes C so great for when both portability and speed are necessary.

    Unfortunately, it hasn't really kept up with the improvements in modern instruction sets. MMX dates back to 1996, and while many people first dismissed it as a gimmick, it proved to be the first of many such SIMD/vector instruction sets. Today, SSE/SSE2 and their successors are a mainstay, especially in applications like video and audio encoding/decoding. Other architectures like ARM also have their own SIMD instruction sets. But C does nothing to support this. There really ought to be SIMD data types and functions built in to the language, rather than having to rely upon compiler-specific extensions or inline assembly language.

    1. Re:Still needed: integral support for SIMD by jeremyp · · Score: 2

      At its core, C is designed to be a sort of portable assembly language.

      No, it was designed as a replacement for assembly language. There's a difference.

      Most of its original features were intended to map directly to PDP-11 opcodes

      This is a myth. Most of C's original features are inherited or evolved from its predecessor languages.

      http://cm.bell-labs.com/who/dmr/chist.html

      Unfortunately, it hasn't really kept up with the improvements in modern instruction sets.

      C has never had any direct support for the instructions of any particular machine architecture. In this, of course, it is in good company with virtually every other non assembly language because, not being assembler, you wouldn't expect it to have direct support for any particular machine instruction.

      There really ought to be SIMD data types and functions built in to the language

      How would you do that in a portable way?

      --
      All I want is a secure system where it's easy to do anything I want. Is that too much to ask ~~ Randall Munroe
  62. Re: by jcdr · · Score: 1

    Yes this is dangerous. Especially when someone will naively translate the "Hello World" into a language that require multiple byte UTF-8 character: the string will grow without notice.

  63. Re: by raynet · · Score: 1

    This new C standard IS a different language, so you should be happy.

    --
    - Raynet --> .
  64. Better fools? by Anonymous Coward · · Score: 0

    Every time you make something foolproof they will invent a better fool.

    Now you have to change the language once or blame the programmers forever

    That's not how it works. You blame the programmers once and change the language forever. See ObjectiveC, C++, Java, C#, etc. for an example.

  65. Let the computer darn your sox and find your bugs. by Ungrounded+Lightning · · Score: 1

    I suspect, though, due to the way you are writing and asking the question, that you've never worked on a large C code base (which if they know what they are doing are already taking the good ideas from OOP methodology - but don't need the "class" keyword as a mental crutch).

    Hear hear!

    If you look at what classes compile to, it's just structs and some syntactic sugar to automatically do what can be easily done manually to manipulate them.

    The main advantage of using the C++ compiler, rather than doing it yourself, is not that the compiler automates the code generation for the manipulation. It's that the compiler always gets it right on what it does for you and can check much of what YOU do to be sure you don't violate intended encapsulation boundaries or point to the wrong thing (unless you use casts to tell it you really meant to do something risky). So there's less opportunity to write a bug and have the compiler accept it.

    ANSI C incorporates some of this with strong type checking (which it got from C++). But a real C++ compiler can make-right-or-detect-error in more ways.

    --
    Bantam Dominique roosters crow a four-note song. Once you've heard it as "Happy BIRTHday" you can't NOT hear it that way
  66. Re:Let the computer darn your sox and find your bu by Ungrounded+Lightning · · Score: 1

    If you look at what classes compile to, it's just structs and some syntactic sugar to automatically do what can be easily done manually to manipulate them.

    Also some const vectors of pointers to functions. Like what you see in kernel driver tables.

    --
    Bantam Dominique roosters crow a four-note song. Once you've heard it as "Happy BIRTHday" you can't NOT hear it that way
  67. What about default arguments? by Anonymous Coward · · Score: 0

    I just wish C would support default arguments. I write a lot of IO drivers and usually the same functions are used for both reads and writes, but some parameters are unused in certain directions. Right now, I just pass NULL, but I would really like to not even have to pass anything. There is a creative solution to the problem over at stackoverflow but it is a bit too much work for my simple cases.
    http://stackoverflow.com/questions/1472138/c-default-arguments

  68. Re: by jeremyp · · Score: 1

    Whoosh!

    Count the number of characters in the string "Hello World".

    --
    All I want is a secure system where it's easy to do anything I want. Is that too much to ask ~~ Randall Munroe
  69. golang by kikito · · Score: 1

    I have started looking at golang, and personally I wouldn't mind it taking over C. I realize it's a completely unrealistic scenario, and others will (strongly) disagree with me. But there you go.

  70. The road to hell is paved by arth1 · · Score: 2

    I blame the programmers not the language.

    I blame the program architects. C isn't the right choice if you want strong typing, bounds checking, auto-alignment, the concept of finite arrays and all the other safety nets.
    C is the right task for some jobs precisely because it doesn't have these features. And the wrong task for many jobs for the same reason.
    Adding features like this reduces C, by making it more like other languages that already are better suited for the job.

    Use C if you can handle all (and I mean all) checking yourself, be it through specs or by adding checks. Otherwise, choose a different language, don't try to transform C into something you want.

    Unfortunately, this fight seems to already have been lost - some of it with C99, and more with C11. So what's a good alternative low level cross-platform language that gives you as much rope as you could possibly want?

    1. Re:The road to hell is paved by bleedingsamurai · · Score: 1

      I can agree with that.

      And that I know of, C is the only language that gives you, low-level manipulation, lots and lots of rope, and is pretty cross-platform.

    2. Re:The road to hell is paved by badkarmadayaccount · · Score: 1

      Ada. PL/I. Lisp Machine Lisp. Oberon Pascal.

      --
      I know tobacco is bad for you, so I smoke weed with crack.
  71. There fixed it. by JustNiz · · Score: 1

    Just use snprintf instead of sprintf.

    1. Re:There fixed it. by petermgreen · · Score: 1

      though snprintf has it's own hazard. It won't directly cause a buffer overflow but it will leave your buffer (which would normally contain a null-terminated string) unterminated so if you don't manually check for failure and either go down an error handling path or manually terminate the truncated string you are likely to get buffer overflows further down the code.

      microsoft's _snprintf_s fixes this but I don't think it's supported outside their tools/libraries.

      --
      note: i'm known as plugwash most places but i screwd up registering that here somehow in the past and now can't register
    2. Re:There fixed it. by JustNiz · · Score: 1

      Why wouldn't you check the return value?
      Anyone who ignores status return values and just assumes every function call worked is going to quickly learn why they need to adjust their approach. That's a good thing.

      I don't think its appropriate for languages to even try and second-guess or otherwise work around lazy/sloppy programming. Its the programmers job to improve, not to botch the system so they can stay crappy.

  72. Re:Oh! by frisket · · Score: 1

    If BASIC was good enough for Jesus Christ, it's good enough for...oh, no, wait...

  73. Re: by JustNiz · · Score: 2

    >> Some how you went from "buffer" to "dynamically allocated memory"

    Yes because if you need a buffer of a length only known at runtime you should be using dynamic memory rather than statically define an array of some guessed length.

    >> 1) your string isn't actually a string because it isn't null-terminated.

    This is only true if you were stupid enough to make your buffer too small, which usually happens because junior or hacky programmers are often inexperienced or hacky enough to incorrectly think guessing a maximum length rather than calculating it is robust.

    >> 2) it is actually more work for you to implement the handling of the error,
    As opposed to what? allowing it to (possibly silently) corrupt memory?

    >> I can't think of too many situations where not having the whole string is useful.
    Nor can I thats why you dynamically create a buffer of suitable length.

    >> By explicitly checking buffer size, I can adjust my destination buffer to include enough space

    Ahh so now we are using dynamic memory?

    >> if it is such a hideous problem I can simply exit() or return

    Wow that must look great to the user. I hope you never write control or embedded software.

    >> At which point why even bother using strncpy() if I'm already checking buffer size manually?

    Both because its safer and can make your code more concise, and because the idea is that if you have a small buffer you should only read as much as you can buffer. The C and C++ language gives you exactly what you asked for. It does not generally coddle ignorant programmers by trying to second-guess everything. I personally love that, as I want a scalpel not plastic scissors.

  74. Re: by fatphil · · Score: 1

    > only use bounded functions like strncpy() rather than unbounded ones like strcpy().

    Use of strncpy() is one of those shibboleths I use to detect if a programmer knows what he's doing or not. If he uses strncpy(), he probably does *not* know what he's doing. He's probably been told by idiots like you that the version with the 'n' is safer, and then uses it without thinking, not even knowing that sometimes it doesn't even leave you with a valid C string. strncpy() is *never* the best solution to a problem. strlcpy() is frequently the best solution, but alas doesn't have enough traction in WG14.

    --
    Also FatPhil on SoylentNews, id 863
  75. Re: by JustNiz · · Score: 1

    You're right in that strlcpy() may be better, however only if you fail to check return values, in which case you're already a lost cause.
    It also doesn't excuse you for being rude and insulting.

  76. Re: safe string copy? by whitroth · · Score: 1

    And what's wrong with strncpy, which I started using heavily after a couple of years of working in C?

    But there is an attitude problem with a lot of coders. For example, I almost *never* use while - 90+% of the time, I use for/next, so I have known limits.

    Too bad so many schools DON'T teach error handling, and so much of upper management demands that programmers write what they want, when they want it, in the time they could wave their hands....

                  mark

  77. Re: by hazah · · Score: 2

    Because it costs extra cycles, and you can't make the assumption that it's neglegable every single time? Because of C's promise that you don't pay for what you don't use? Because it's a logic error to begin with and you should fix your logic errors, program your intent, and not rely on the compiler to figure out what you meant? Because you want to control the binary output?

    Take your pick.

  78. Re: safe string copy? by hawguy · · Score: 1

    And what's wrong with strncpy, which I started using heavily after a couple of years of working in C?

    But there is an attitude problem with a lot of coders. For example, I almost *never* use while - 90+% of the time, I use for/next, so I have known limits.

    Too bad so many schools DON'T teach error handling, and so much of upper management demands that programmers write what they want, when they want it, in the time they could wave their hands....

                  mark

    The problem with strncpy() is that it can leave you with a non-null terminated string which can cause problems later on if you're using a function that expects a null terminated string. So you end up having to manually check the size of the copied string to see if it was larger than your destination buffer minus 1 so you can warn someone that the whole string wasn't copied, or just you blindly terminate the last byte of the buffer to prevent problems later on.

    Much safer to use strncpy_s() since it will null terminate the destination string automatically and you can check the return code to see if the entire string was copied or not.

    http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf

    errno_t strncpy_s(char * restrict s1, rsize_t s1max, const char * restrict s2, rsize_t n);

    The strncpy_s function copies not more than n successive characters (characters that
    follow a null character are not copied) from the array pointed to by s2 to the array
    pointed to by s1. If no null character was copied from s2, then s1[n] is set to a null
    character.

    A zero return value implies that all of the requested characters from the string pointed to by s2 t
    within the array pointed to by s1 and that the result in s1 is null terminated.

  79. Re:What about allowing a '&int' as a declarati by hazah · · Score: 1

    typedef int* intptr; done :).

  80. Re: by sjames · · Score: 1

    Back in my day we programmed in binary by writing the program directly to the drive using a magnetized nail and that's the way we liked it. You young kids are gonna burn in hell with your newfangled built in bounds checking. Life is supposed to hurt damnit and if it doesn't hurt enough we have to MAKE it hurt. Now shut up while I clamp my balls in this vice!

    If you hate the built in bounds checking so much, don't use the *_s functions.

  81. Re: by bleedingsamurai · · Score: 1

    See, now you are just twisting the whole "buffer" and "dynamically allocated memory" thing and just using whichever term when it suits you.
    When I pointed out you where going from one to the other it was because you questioned me, asking how I thought printf("hello world\n"); uses any dynamic memory when I never said such a thing, I specifically said "buffer"

    Not necessarily. I agree that simply guessing at the max size of a buffer is incorrect. But I think it is better to start out with a max guess with the option to calculate and adjust as needed. On most platforms it is more expensive to actually allocate new memory then to simply have one big allocated at program start chunk.

    You shouldn't criticize a simple call to exit(), it is impossible to think up every single thing users will throw at your program. I think the best approach is to try and figure out the most common errors and create code that adjusts for them, then a generic handler that either calls exit() or returns and lets the calling function decide what to do based on the return value is a good catch all. Even then you arn't completely covered.
    What about race conditions? Is it really better to try and hide the fact that data was incorrectly processed, or instead, having realized data is incorrect, calling exit() because it wouldn't make any sense to continue. (though we should try to avoid race conditions!)
    What if I run:
    yes $VERY_LONG_STRING | your_program
    It just can't continue calculating the length of the string, at some point it has to say "this is too long" and exit.
    I tend to stick with systems programming, I never got into hardware that much.

    I completely agree with the second and third statement of your closing. However the first one, eh. I just don't see how functions like strncpy() are that big of a difference then how things where done before. It is perfectly possible to write code with strcpy() for example, and not leave openings for buffer overflows. I just feel like they are changing the language for the sake of changing it. And I also feel like the more functions like strncpy() that get pushed into the standard library, the closer we are to taking way the power that C gives you by doing what you asked for.

  82. Have you ever used C++? by Anonymous Coward · · Score: 0

    Automatic memory management? Isn't this what makes C++ so fucking insanely complex?

    C++ has no intrinsic automatic memory management facilities. Not in the C++98 spec, not in TR1, not in C++11. The programmer can choose to encapsulate a pointer inside an auto_ptr or a shared_ptr or what-have-you, but it's not automatically done. Garbage collection isn't part of the spec and likely will never be.

    Overloading? Umm, that's extremely dangerous in subtle complex code like operating system schedulers, computational code, etc. Very bad idea.

    Right, because for matrices foo.multiplyBy(bar.multiplyBy(baz.invert())) is so much easier to read than foo * bar * -baz. Operator overloading can certainly be used in stupid ways, but that's no reason to prohibit operator overloading.

    It's worth noting that Java overloads operators left and right. Have you ever noticed that you can use "+" to add an int to a float, two ints, two floats, or to (gasp!) concatenate two strings?

    Inheritance? Nah. Almost as bad as overloading, but also useless for most most activities.

    Assuming arguendo that you're right (and you're not), is that a reason to prohibit inheritance? You yourself say there are areas where it's useful, so perhaps it should be included in the language for the benefit of programmers who are working in that domain.

    Templates? No, they're even worse than overloading. I suppose Java interfaces or Haskell typeclass could provide a safe form of overloading.

    Okay, so here it's really clear you've never used templates at all. Templates are typesafe. In fact, C++ templates are almost as typesafe as ML or Haskell. If the compiler can't unambiguously determine at compile-time what types are going to be used, that's a compilation error.

    Lambda expressions, ala C++0x? Interesting proposal, not exactly sure how the memory management works out

    A lambda expression is just syntactic sugar for creating an anonymous struct. It uses the exact same "memory management" that every other variable declared on the stack does.

    C must avoid the mad dash into standardization that created C++'s complexity.

    Listen, kid, I started writing C++ in 1989. Back then it was almost a decade old. It wouldn't get standardized until 1998. The first appendix didn't come along for five years after that, and the new revision of the standard was eight years later. In what bizarro world is this 'rushing into standardization'? If you want to say that about Ada83, go for it: yes, Ada83 was rushed and it shows. But the biggest complaint about the C++ standardization effort is that it's taken too long and the design committee is too conservative, not that it's been rushing headlong into things.

    As an example, consider C++ concepts. Concepts were, are, a great way to resolve certain systemic shortcomings of C++. They got yanked from C++11 at the last possible minute despite being a fairly well-understood feature, because the committee wasn't quite sure the feature was mature enough for inclusion.

    I can't tell if you're trolling or if you're just this badly ignorant of the C++ language. If the former, then have a nice day, I have been trolled. If the latter, I strongly urge that you spend a couple of years writing code in C++ and discovering the breadth and depth of the language. You might, like me, find yourself liking it an awful lot.

  83. Re: by JustNiz · · Score: 1

    >> But I think it is better to start out with a max guess with the option to calculate and adjust as needed.

    Not at all. You should NEVER guess first then readjust. ugh that idea sucks balls.

    I agree you may need to define a practical limit but you should use the same limit in both the buffer size calculation and the read operation (or whatever) that fills it (which is where and why functions like stricpy() and strncpy() have value over strcpy() ). That way you don't need to ever worry about crashing the buffer or dynamically resizing it. You also need to share any limitation as a design constraint with the users/callers of your code.

    >> You shouldn't criticize a simple call to exit(),
    I will when the need for it to even exist is retarded, as it is simply being used to handle failures caused by bad programming approach rather than a lack or failure of system resources.

    >> What about race conditions? Is it really better to try and hide the fact that data was incorrectly processed,

    OK what race condition are you expecting in hello world?
    You're just trying to muddy the water by bringing in multi-threaded or multi-process issues, but to answer it anyway, if the environment is multi-threaded you should be using the appropriate locking or synchronisation mechanism (e.g. semaphores, mutexes, critical sections, events etc) around the shared resource to completely prevent race conditions.

  84. Because You Should Be A Better Human by Anonymous Coward · · Score: 0

    ..then Socialism would actually work !!

  85. I disagree by Anonymous Coward · · Score: 0

    The ability to have safe arrays (and safe pointers ?), which you can selectively turn off - that would be a great improvement. Typically, 20% of your code make for 80% of execution time. For the 80% scarcely used code, it would be good to have bounds checking turned on by default.