News for hackers. Stuff that matters.
Re:Microsoft to C99 Developers: Use ISO C++ by dsrguru on Monday May 07, 2012 @12:21PM (#3939636)
There might be some merit to this. If you want a language that is very portable and has a definition that is compact enough to be fully understood both by you and by programs you might write that operate on source code (static analyzers, interpreters, compilers, etc.), you are probably going to use C89/90 instead of C99 (at least that seems to be what K&R felt--and what K still feels). Otherwise, what advantages do you have in going with pure C99 over the C99 almost subset of ISO C++? Even if you don't really use any language features unique to C++, you would still get some safer library functions and better portability than you would if you limited yourself to the C99 standard.
Re:Microsoft to C99 Developers: Use ISO C++ by haberman on Monday May 07, 2012 @12:38PM (#3939735)
> If you want a language that is very portable and has a definition that is compact enough to be fully understood both by you and by programs you might write that operate on source code (static analyzers, interpreters, compilers, etc.), you are probably going to use C89/90 instead of C99

C99 has some very hard-to-replicate features; most notably designated initializers. Without them, you cannot statically initialize any union member except the first. This is a significant problem for me.

C99 is mostly supported by every C compiler I am aware of except MSVC, so it would be portable if not for Microsoft.

> Even if you don't really use any language features unique to C++, you would still get some safer library functions and better portability than you would if you limited yourself to the C99 standard.

C++ is not available in the Linux kernel, it mangles names, and it's tricky to be disciplined enough to write in a C++ subset without letting C++ features creep in, especially on a multi-person project. Once you let C++ features creep in you can inadvertently end up with runtime static initializers, type_info symbols, exception unwinding code and debugging symbols, etc.

My current compromise is to compile as C99 everywhere except on MSVC, where I will compile as C++ and use C++ alternatives to features like designated initializers.

Re:Microsoft to C99 Developers: Use ISO C++ by chocolatebunny on Monday May 07, 2012 @02:37PM (#3940315)
What's the C++ alternative to designated initializers?
Re:Microsoft to C99 Developers: Use ISO C++ by stephencanon on Monday May 07, 2012 @02:55PM (#3940424)
Constructors, I would assume, but that's not a very attractive alternative in my opinion.
Re:Microsoft to C99 Developers: Use ISO C++ by haberman on Monday May 07, 2012 @09:33PM (#3941759)
With C++11, you can use constexpr constructors to guarantee that they run at compile-time and end up as flat data in the .data/.rodata section instead of run-time static initialization. Or so I'm told by the C++11 people I asked about it.
Re:Microsoft to C99 Developers: Use ISO C++ by comex on Monday May 07, 2012 @12:36PM (#3939717)
If MSVC supported C99, it would be portable enough for the three major platforms plus all the ports of GCC and any analyzers written for Clang/LLVM. What do you get versus C++? Implicit casting of void *, so you don't have to repeat yourself every time you use malloc, restrict, structure literals, faster compilation (yes, the same code compiles faster in C mode than C++ mode, at least in gcc), not having to remember slightly different rules about scoping, ...
Re:Microsoft to C99 Developers: Use ISO C++ by comex on Monday May 07, 2012 @04:07PM (#3940744)
Self-reply: That's only C99, by the way. Compared to C++11, C11 adds anonymous structs, and incompatible handling of atomics, noreturn, and even generics.
Re:Microsoft to C99 Developers: Use ISO C++ by dsrguru on Monday May 07, 2012 @01:00PM (#3939843)
What do you typically use in C99 that you don't get in C89?
Re:Microsoft to C99 Developers: Use ISO C++ by _delirium on Monday May 07, 2012 @02:21PM (#3940223)
A few things I like, though not all of them are strictly needed:

    long long foo; /* bigger ints on 32-bit platforms */
    uint32_t bar;  /* stdint.h, integers of specific bit width */
    int array[n];  /* length-n array, where n is a variable */
    for (int i = 0; i < n; i++) /* loop-local variable */
Also, the safer stdio functions like snprintf.
Re:Microsoft to C99 Developers: Use ISO C++ by yuhong on Monday May 07, 2012 @03:45PM (#3940628)
Some of them are already in MSVC.
Re:Microsoft to C99 Developers: Use ISO C++ by stephencanon on Monday May 07, 2012 @02:36PM (#3940312)
Off the top of my head, C99 features that I've used in the past couple months:

  - declarations mixed with statements
  - declarations in `for` constructs
  - hexadecimal floating-point literals and conversion specifiers
  - the strtoxx( ) conversion routines
  - the restrict qualifier
  - the expanded math library
  - designated initializers
  - extended integer types
  - compound literals
  - // comments
  - VLAs
  - complex support
Note that some of these features are still not present in C++11.

C11 features that I have used in the past few months:

  - CMPLX macros
  - anonymous structures and unions
  - <stdalign.h>
Re:Microsoft to C99 Developers: Use ISO C++ by onedognight on Monday May 07, 2012 @02:38PM (#3940323)
I miss C99 named initializers even in C++.

    struct { struct y y; bool flag; } = { .flag = true };
Re:Microsoft to C99 Developers: Use ISO C++ by oconnore on Monday May 07, 2012 @01:22PM (#3939946)
'for' loops
Re:Microsoft to C99 Developers: Use ISO C++ by EvilTerran on Monday May 07, 2012 @01:23PM (#3939951)
C++'s name mangling feels like a dealbreaker to me; it really hurts interoperability with other languages.

In general, C feels well-suited to be the language that (almost) every other language can talk to; C++ just doesn't fit that role so well.

Re:Microsoft to C99 Developers: Use ISO C++ by Erwin on Monday May 07, 2012 @02:03PM (#3940152)
You can explicitly export functions you want available outside, disabling the name mangling (using export "C").

I'm not sure how else you think C++ could handle its goals without the name mangling: overloading and compatibility with C's linker system. If you have two overloaded "foo" functions you need to somehow designated them as separate linker symbols.

C has similar problems of its own: like what's the calling convention for the exported symbol? Do I push the arguments on the stack, and who cleans up? Do some arguments go into registered? Where does the return value go? What's the layout of a struct? All things are platform, compiler and compiler configuration dependent.

What other languages, that compile to object files or shared objects, that support the level of OO features etc. that C++ has, have a well-defined ABI?

Re:Microsoft to C99 Developers: Use ISO C++ by tjr on Monday May 07, 2012 @12:30PM (#3939686)
In avionics development, having a compiler certified for production use is a big (expensive) deal. Accordingly, you'll still find avionics people using C89 if for no other reason than because they certified a C89 compiler years ago and it still works.
Re:Microsoft to C99 Developers: Use ISO C++ by TazeTSchnitzel on Monday May 07, 2012 @12:29PM (#3939680)
These are my feelings too. C++ is not supposed to be object-oriented C, rather, it is supposed to be an improved C with more features, one being language support for OOP. You might as well just use C++.
Re:Microsoft to C99 Developers: Use ISO C++ by tmhedberg on Monday May 07, 2012 @12:57PM (#3939829)
Perhaps C++ is mostly a superset of C in a technical sense, but in practice, it comes with its own idioms, its own conventions, its own design patterns, and its own culture, all very distinct from those of C. There's far more to consider when selecting a programming language beyond "Does Language X have a superset of the features of Language Y?".

Plus, sometimes having fewer features is itself a feature. I would say that this is especially true when comparing the slim, minimal design of C with the "everything and the kitchen sink" approach of C++. Not that C++ is never useful in its own right, but that doesn't mean its appropriateness for a given task is always greater than or equal to that of C.

Re:Microsoft to C99 Developers: Use ISO C++ by TazeTSchnitzel on Monday May 07, 2012 @01:04PM (#3939857)
With C99 and C11 though, C is becoming larger and less minimal. I'm not sure that argument still applies.
Re:Microsoft to C99 Developers: Use ISO C++ by derleth on Monday May 07, 2012 @02:30PM (#3940263)
> an improved C with more features

This mostly means it's incompatible with C even in the parts of the language both of them share. Completely valid and idiomatic C code will therefore not always compile if you use a C++ compiler.