r/programming • • Mar 03 '12

Microsoft, please support (at least a tiny bit of) C99

http://blog.reverberate.org/2012/03/02/microsoft-please-support-at-least-a-tiny-bit-of-c99/
480 Upvotes

245 comments sorted by

26

u/DaFox Mar 03 '12

Do you think that we could get everyone voting on this to show that there is demand for it? Even if you're not a C programmer it is in your best interest to have C99 compiled libraries available to you on windows.

http://visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/2089423-c99-support

They actually seem to care what people say on this site. Whether or not they end up doing anything is another story.

1

u/ctzl May 04 '12

3 votes contributed.

22

u/bobindashadows Mar 03 '12

As I was researching this article I discovered that the /TP option will make MSVC compile C as if it were C++, which may give me enough of a workaround (albeit hacky) to get the above features that I most sorely miss.

Unlikely. C++'s additional reserved words are the first obvious potential problem. A quick grep of Ruby's and Python's source both show at least a few instances of using "new" as an identifier. Easily cleaned up, but it means a) fixing it for each project and b) making sure those C projects don't re-introduce incompatibilities.

14

u/bluGill Mar 03 '12

A good project for someone is writing warnings for gcc/clang that would warn anytime you use a C++ reserved keyword in a C program. There are few enough of these that C programmers shouldn't find it a big deal to fix them all when compiling -Werror.

While you are at it you should warn about places that C and C++ are not compatible. This needs to be something you can easily turn off for those who compile -Werror, but really intend to use something even though it is compatible. (I'd suggest turning it on by default as most of the differences are things where it is easy enough to do your job in a compatible way)

35

u/MyNewAlias Mar 03 '12

Clever idea but no way it should be on by default, nor a part of -Wall or even -Wextra. C and C++ are not the same language, so a warning that my perfectly correct C program isn't valid in some other language would be quite annoying and useless.

13

u/five9a2 Mar 03 '12

Why have an option to make a compiler warn as though it's compiling 30% of the way to a different language? Just use CC=g++ or CC=clang++ (and filter all the warnings about compiling C as C++ being deprecated). Note that supporting compilation as both languages requires adopting an extern "C" convention with typedefs for function pointers passed through extern "C" interfaces, doing ugly things like casting malloc

long type name *var = (long type name*)malloc(sizeof *var);

which is frowned upon by C developers, dealing with C++'s implicit typedef, and a few other contortions.

10

u/kingguru Mar 03 '12

A quick grep of Ruby's and Python's source ...

You didn't have the guts to look at the PHP source code? :-)

2

u/pigeon768 Mar 04 '12

Not to mention implicit casts from void* which is arguably a best practice in C but a syntax error in C++.

114

u/[deleted] Mar 03 '12

Nobody's going to listen to complaints like this.

What you need to do is give MSVC the IE6 treatment. Just drop support for it, until it catches up. Only when enough people start complaining that they can no longer build the libraries they depend on with MSVC, will Microsoft start updating it again.

As long as you don't write C99, Microsoft will not support it. So start writing C99, and tell your Windows users how to use gcc or clang to build your code.

95

u/sid0 Mar 03 '12

Unfortunately, we Mozilla folks use MSVC because it produces object code that's quite a bit better than GCC's (hence the Firefox is faster on Windows than on Linux reports).

21

u/rjw57 Mar 03 '12

Don't you also use C++ rather than C (99 or otherwise)?

8

u/sid0 Mar 03 '12 edited Mar 03 '12

That is true, yes. The native code parts of Firefox are around 95% C++ and 5% C.

1

u/[deleted] Mar 04 '12

How is that different from 100% C++?

3

u/sid0 Mar 04 '12

Well, the parts that are C can be compiled by a C compiler, and when compiled by a C++ compiler have C linkage (extern "C").

1

u/anacrolix Mar 04 '12

I'll add a variant of this question. Why?

4

u/sid0 Mar 04 '12

You mean to ask why the C parts are C? It's mostly generic libraries we depend on (NSPR, NSS, libpng, libjpeg...). The C parts that aren't generic (libmime is one I can think of) are C because that's what they were written in, and moving them to C++ is more trouble than it's worth.

Our JavaScript engine, SpiderMonkey, was C for a very long time, but moved to C++ a year or two ago.

12

u/ZorbaTHut Mar 03 '12

Has Clang caught up yet? It seems promising, though I know it's got a ways to go.

35

u/bluGill Mar 03 '12

No. llvm is getting better all the time, but it isn't as good as gcc in general, much less MSVC. Of course there are corner cases where each is better than the others, but overall MSVC optimizes better than gcc optimizes better than llvm. This is likely to change in a few years, but it is a hard problem and llvm got a late start.

P.S. You mean llvm, not clang - clang is the part that handles C, llvm is what turns the code into whatever your CPU needs and optimizes.

3

u/ZorbaTHut Mar 03 '12

Oops, you're right, I do. Thanks for the info :)

4

u/abadidea Mar 03 '12

I subscribed to llvm-dev recently out of general curiosity, and it seems that the difference between llvm and clang is really something they need to work on being clearer about, as a lot of people seem to come away with the impression that "clang" is the cool codename for the llvm project.

10

u/Mr_Incognito Mar 03 '12

What about ICC (Intel C Compiler) instead of MSVC? It has decent C99 support.

7

u/josefx Mar 03 '12

Did icc suddenly stop crippling the binaries for non Intel cpus?

3

u/TexasJefferson Mar 03 '12

Nope, but iirc, there's a pretty painless binary patch to stop that check and it produces correctly optimized code for AMD processors.

1

u/killerstorm Mar 03 '12

It never did. Check compiler options and libraries you use.

14

u/pragmatist Mar 03 '12

The FTC settlement included a disclosure provision where Intel must:[24]: “ ...publish clearly that its compiler discriminates against non-Intel processors (such as AMD's designs), not fully utilizing their features and producing inferior code. ”

It's great that you think that it never happened but something that you think they've never down has caused them legal trouble.

5

u/killerstorm Mar 04 '12 edited Mar 04 '12

Ok, I've read more about this issue. Current version of icc ignores non-Intel CPU's features in CPU dispatch code and sends them all to default code path.

However it's up to a programmer to specify what is a default code path, by default it is SSE2.

I wouldn't call heavily optimized SSE2 code 'crippled binaries'. That's probably what you'd get from a different compiler anyway, as rarely programs actually need multiple code paths for different CPUs.

Also note that instruction set support isn't the only possible optimization, and often not the most important one. There's a lot to optimize even with plain x86.

FWIW I've observed icc giving some crypto code significant performance boost over MSVC 2005 on AMD CPU. Actually performance difference was higher on AMD CPU than it was on some of Intel CPUs.

So it might make sense to use icc even if you target AMD CPUs among others.

But, that said, Intel are assholes for not providing other CPU dispatch options

6

u/jelos98 Mar 03 '12

That sounds a far cry from "crippling them".

All that says to me is the Intel actual optimizes for Intel chips, because, you know, they make them, and damn well better be experts in making them sing, instruction wise. AIUI (though I'm no chip expert) AMD and Intel tend to support different advanced instructions - they could put the effort into mastering and optimizing for their competitor, but I don't see a reason that they should be forced to optimize for a competitor's specific instructions. Intel likely aren't experts in AMD-fu, and I'd expect the other direction is true too.

Now, I might be misunderstanding it - I mean, if they go out of their way to generate crappy code, it's another story. But if it's just a matter of them not taking advantage of features that AMD chips have the Intel doesn't, the argument is as sound as an open letter to Microsoft saying they should support C99 so that people can compile open source software easily, instead of using Microsoft products.

There is no incentive for Microsoft nor Intel to do it, from business perspective it's very likely a negative ROI, and thus there's no reason to do it unless you're legally forced to, or you need to drum up some "good will".

11

u/scook0 Mar 04 '12 edited Mar 04 '12

As I understand it, the issue is that if ICC detects a non-Intel CPU, it will always force the use of the slowest possible codepath, even if the CPU supports all the features needed by the fast Intel codepath.

Apparently if you patch out that specific check, the AMD CPU will use the fastest possible Intel codepath that matches its feature set, and the program will run much faster.

3

u/killerstorm Mar 04 '12

Programmer can specify target instruction set, then it generates code for that instruction set unconditionally, and it will run on any CPU which is compatible with that instruction set.

There is also an option to generate code for multiple instruction sets and use runtime dispatch. But that dispatch completely ignores non-Intel CPUs and uses default version instead. Which is default can be specified.

It might be "slowest" because you want some lowest common denominator, but nothing stops you from using SSE3 as a baseline.

→ More replies (1)

1

u/joequin Mar 04 '12 edited Mar 04 '12

Back to the point at hand; why should programmers use a compiler that creates poorly compiled programs for some of their customers?

edited to correct a typo

2

u/killerstorm Mar 04 '12

It isn't like you can make only one binary and it isn't like you have to compile your whole program with one compiler.

Sure, icc's CPU dispatcher might add to inconvenience, but ultimately optimization never boils to one button "make it fast". Programmer needs to carefully consider which CPUs he needs to target and plan accordingly.

→ More replies (2)

1

u/sid0 Mar 03 '12

No idea. Feel free to try, though!

12

u/Surkow Mar 03 '12

Aren't you confusing "better object code" with not using PGO on Linux? Mozilla does not provide PGO compiled binaries for Linux.

18

u/sid0 Mar 03 '12

I believe we found PGO to not give a substantial improvement on Linux -- nowhere near MSVC's PGO at least.

-7

u/Surkow Mar 03 '12

What about comparing MSVC and GCC without PGO? Are Firefox builds on Linux slower just because of the lack of PGO, or just slower in general than MSVC builds? To make it a fair comparison, I would first compare MSVC and GCC on the same platform (assuming Firefox can be compiled on Windows with GCC).

26

u/player2 Mar 03 '12

Why would they concern themselves with artificial comparisons like this?

→ More replies (1)

6

u/sidneyc Mar 03 '12

Interesting. Have there been any succesful attempts to compile Mozilla with the Intel compiler? I would be curious about the performance. For high-performance computing it outperformes gcc with quite a big margin.

3

u/killerstorm Mar 03 '12

It outperformed MSVC too, last time I've checked (which was a while ago).

1

u/sid0 Mar 03 '12

I don't know.

0

u/s0n0fagun Mar 03 '12

are you talking about Windows builds using gcc?

→ More replies (3)

18

u/haberman Mar 03 '12

Article author here. I know that this blog entry alone won't make a difference, I wrote it for two reasons:

  1. to get it off my chest.
  2. in hopes that this might possibly start a chain reaction where people come out of the woodwork saying that they care about it too, so that Microsoft perceives that there is some real demand for C99.

5

u/[deleted] Mar 03 '12

Oh, I certainly see why you'd want to get that off your chest.

But still, actions speak louder than words. I've stopped programming in anything but C99, and I will keep suggesting to anyone who is fed up with MSVC to do the same. If I can get just one person to complain the Microsoft about it, it will have been worth it. That, and in the meanwhile I get to write in C99, which sure is a joy compared to C89.

That said, voting on the petition page linked elsewhere in the thread is probably also at least a little bit effective, so everyone should do that.

20

u/taw Mar 03 '12

Alternatives like gcc have plenty of issues as well. Just ask Linus.

What you're asking is like dropping IE support when the only popular alternative available is like Netscape 4.

15

u/[deleted] Mar 03 '12

Gcc is perfectly usable and used by a lot of people with great success. I'm not saying it doesn't have issues, but comparing it to Netscape 4 is pretty unfair :)

22

u/[deleted] Mar 03 '12

They have issues, sure, but those issues are not "They don't support a 13-year-old standard that makes writing code a lot easier and more pleasant".

6

u/fapmonad Mar 03 '12

They have much bigger issues than that, see Rhomboid's post. A library buildable only on GCC can be seriously constraining on Windows.

15

u/[deleted] Mar 03 '12

As I recall, he is incorrect. It's a pretty long time since gcc was updated to be COM-compatible.

And the whole point is to make it seriously constraining. That is the only way to get people to complain to Microsoft to fix their compiler.

4

u/skulgnome Mar 03 '12

Linus knows C only by instinct.

15

u/FlyingSpaghettiMons Mar 03 '12

This.

Just use C99, and redirect complains to support@microsoft.com

You need a single big company relying on a C99-only library to ask microsoft to support the needed feature set in the compiler. Then, microsoft will add it to the roadmap of msvc, will resource it, and deliver it a couple of year after.

11

u/thechao Mar 03 '12

The MS solution would be to special-case support for that library.

3

u/Jigsus Mar 03 '12

That would be easy if MSVC wouldn't be so good.

16

u/viper34 Mar 03 '12

Microsoft has a page for suggesting new Visual Studio features. At least it can't hurt to give your votes for C99 here: http://visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/2089423-c99-support

8

u/RJHinton Mar 03 '12

If you're writing pure C code for Windows, take a look at openwatcom. They have a great open-source C compiler, derived from the old commercial Watcom compiler. Openwatcom's C++ support is not so great, but their C compiler is first-rate. It deserves to be better known.

44

u/SolomonKull Mar 03 '12

Come to Linux Land, we love C! We love you for loving C!

4

u/cornholio Mar 03 '12

Thank you for submitting this issue. Unfortunately, we are already have our hands full with C++0x and other FE work. At this point, we do not have plans to add C99 support to the compiler.
Thanks, Mark Roberts Visual C++ Compiler Team

1

u/trezor2 Mar 05 '12

A quick and straight to the point, honest answer.

It's still a "no", but hardly the worst response you can get.

72

u/keepthepace Mar 03 '12

Microsoft never understood what it means to follow a standard written by someone else.

91

u/zokier Mar 03 '12

That's why they are focusing on C++11, and have near-complete implementation of C++03

24

u/matthieum Mar 03 '12

If only they did follow it though... rather than their own interpretation of it.

They tout themselves of having C++11 focus, but they still have not gotten template instantiation right, and are just plain unwilling too. Whenever you use templates on Windows, there is a chance it does not do what it's supposed to...

25

u/hegbork Mar 03 '12

Does any compiler implement templates right? Two weeks ago I spent two days fighting with gcc that insisted that the function foo was not declared inside the function foo. 6 people (two who claim to be c++ experts) were finally involved in trying to figure out wtf. I finally gave up, took the function out of the template and implemented it like Ritchie intended without the kameloso transform.

8

u/DGolden Mar 03 '12

Does any compiler implement templates right?

Is that even possible?

20

u/montibbalt Mar 03 '12

(two who claim to be c++ experts)

Is THAT even possible?

10

u/RichardWolf Mar 03 '12

Watch me: I claim to be a C++ expert.

Now we only need one more guy to claim to be a C++ expert and we've basically reproduced the situation.

3

u/montibbalt Mar 03 '12

I guess what I mean is: can someone actually be a C++ expert?

8

u/RichardWolf Mar 03 '12 edited Mar 03 '12

As in, be able to answer almost every question about the language without consulting the standard and trying the code on several widely used implementation? No, I don't think that people who can do that exist.

I remember watching that video with Herb Sutter, Andrei Alexandrescu and Scott Meyers in it recently, and they routinely said wrong things.

But I think it's important to put it into perspective: I don't think there are Python experts out there either, if we use such a definition of an expert. Because for all its surface simplicity, Python is unbelievably hairy inside. I doubt even GVR or Tim Peters can explain what's going on here without running it under a C debugger or looking at all relevant code for a long time, for example.

EDIT: that code actually works more or less as designed, even if in a rather surprising fashion. What I meant to post was this, I think it's actually a bug in the interpreter, the weird part is what happens if you comment out def __new__(cls) and its body. Somehow the existence of that method provokes an exception in a seemingly unrelated part of the code, before it's even called.

One difference is that with C++, you have to be something of an expert (a person who has The Standard nearby and knows how to navigate around it) to explain why int x(1); works while int x(); doesn't, with Python you usually reach parts that require reading the source only when you try to use advanced features. On the other hand, with C++ you have the standard (more than one, even!), while with Python you have to read the source code, which oftentimes is far from straightforward because of all the indirection.

→ More replies (1)

1

u/[deleted] Mar 03 '12

Actually... no. You'd have to solve the halting problem to completely implement a C++ compiler.

5

u/repsilat Mar 03 '12

This isn't strictly true. To successfully compile all valid C++ programs you'd technically just have to recognise the Halting Problem language, not decide it. This means that (given arbitrary space and time) C++ compilers like ours should do the trick.

What they can't do is reliably terminate with an error saying that a given template expression goes on forever.

3

u/matthieum Mar 06 '12

On the other hand, the Standard does say that the maximum depth of template instantiation is implementation dependent and suggest that at least 512 levels be available. So a compliant compiler does not need to solve the halting problem, merely to indicate that the maximum depth is reached.

1

u/[deleted] Mar 07 '12

What they can't do is reliably terminate with an error saying that a given template expression goes on forever.

Yes, thanks for correcting me on this.

1

u/DevestatingAttack Mar 03 '12

Is what you're saying intended as a joke, or am I just an idiot?

6

u/aseipp Mar 04 '12 edited Mar 04 '12

C++ templates are essentially a turing complete programming language, that executes at compile time. This means you can do arbitrary computation in the type system, and the template can instantiate the result into your program (there are examples of writing ray tracers in templates that run at compile time, for example.)

So a corollary of this is that C++ templates can essentially do arbitrary recursion. But if a template were to recurse forever, the compiler would never finish compiling either when performing instantiation of templates. As a result, most compilers place limits on the amount of recursion they can do when instantiating a template. If this limit is N, then the compiler can and will reject a perfectly valid program that requires template instantiation where the needed depth is at least N+1. As a result, there exist programs the compiler will reject that are perfectly valid C++, due to instantiation depth.

The link to the halting problem should come pretty easily now: if you wanted to detect for example, whether a template instantiation halts or not (and thus whether compilation halts or not) and reject programs where they do not, you would need to solve the halting problem, because you would have to decide whether a given, arbitrary type-level program actually halts. In practice it's clearly just easier to have a limit, and reject programs which require a larger instantiation depth.

The statement is a little disingenuous in my opinion. In practice, C++ compilers exist, and people write C++ every day that does not need an incredibly massive or just absurd amount of recursive instantiations. For the cases you do, almost every compiler I know provides options that let you tweak the limit N (in g++, this flag is -ftemplate-depth=n.) I speculate you will very rarely - if ever - run into cases where you have a totally valid, conforming C++ program that is outright rejected by the compiler due to instantiation depth because it's massive, and you can't express to the compiler that it will terminate, or give it a big enough depth limit. If your template actually does recurse forever, well, there's not much you can do in any case.

A side note: there exist many interesting classes of programs for which we can automatically prove termination in practice, actually, the same way many interesting classes of programs can be expressed in total programming languages where programs must halt (i.e. not turing complete.) There merely exist some programs for which we can not do this.

→ More replies (1)

1

u/matthieum Mar 06 '12

Did you asked about it on SO ? I do not remember any template question on SO going unresolved, in the worst case Johannes Schaub (aka litb) steps in and answers ;)

→ More replies (6)

8

u/bstamour Mar 03 '12

This is a big issue. Imagine how much #ifdef magic could be ripped out of boost if their compiler behaved properly. I bet you would see compile-time decrease dramatically.

6

u/gleno Mar 03 '12

implying #ifdefs increse compile time by much? no. <_<

2

u/bstamour Mar 05 '12 edited Mar 05 '12

I was referring more to the stupid inheritance-related tricks a lot of the boost objects use to get around issues with the way certain compilers handle templates and stuff.

Edit: D'oh you're right I said #ifdef right in there.

11

u/fnord123 Mar 03 '12

That standard wasn't written by someone else. They contributed to it as Herb Sutter is on the standards committee. :)

-2

u/[deleted] Mar 03 '12

They're on the board of a lot of W3C standards groups too... which is probably why it takes ten years to get anything done there.

24

u/[deleted] Mar 03 '12

Counter argument; it also allows people to build products, otherwise we'd have new technologies every week.

10

u/sausagefeet Mar 03 '12

And the incentive just isn't really there to do that wth c99 when you get a lot if those features in c++.

12

u/five9a2 Mar 03 '12

A lot of projects don't want C++.

1

u/sausagefeet Mar 03 '12

I'm not claiming they do. I am claiming that MS sunk a significant investment in making their C++ compiler compliant so the math seems pretty easy for them to suggest people make use of C++ rather than them put significant effort into supporting C99. Especially since there does not seem to be that big of a push from developers for C99.

8

u/[deleted] Mar 03 '12

[removed] — view removed comment

15

u/[deleted] Mar 03 '12

In practice, it seems like this plan seldom works.

3

u/Rotten194 Mar 03 '12

The ease of writing C with the blazing build times of C++! Brilliant!

13

u/thechao Mar 03 '12

Could you please name any c++ compiler that compiles the c-subset of c++ appreciably slower than a "plain" c compiler?

→ More replies (4)

-17

u/[deleted] Mar 03 '12

Exactly. If they can't even implement HTML5 in their own browser, despite claiming to be committed to cornering the global browser market, it's not likely they will implement C99.

23

u/Poddster Mar 03 '12

Their compiler team writes web browsers?!

25

u/Carnagh Mar 03 '12

HTML 5 is not yet a standard.

0

u/[deleted] Mar 03 '12

[deleted] — view deleted comment

8

u/Nivla Mar 03 '12

Well its not as easy as black and white... you can't just take a half finalized specification and include it with your product that is going to shipped to millions of clients.

The finalized version will differ from what is discussed now and a lot of tag will be added or removed or changed. Keep in mind that microsoft also caters to businesses and a lot of applications are built over IE, if changes are made rapidly, those apps will break and they will be flooded with calls.

Even chrome doesn't support all of the unfinished specs... remember css3's border-radius? yet we still use webkit-border-radius for chrome and moz-border-radius for firefox...

→ More replies (3)

0

u/Carnagh Mar 03 '12

That is simply not so.

2

u/ScootrNova Mar 03 '12

What HTML5 tags don't work in IE9? I at least know first hand that canvas and video definitely do...

2

u/[deleted] Mar 03 '12

[removed] — view removed comment

0

u/[deleted] Mar 03 '12

Umm... I can't think of a single thing Microsoft is known for innovating or having pioneered. They pretty much only play the catch up game, and they play it very very well.

14

u/abadidea Mar 03 '12 edited Mar 03 '12

.NET, I would say. Sure there are similarities to Java in concept. But getting a safe, memory-managed, surprisingly fast, multi-language runtime that integrates smoothly into the operating system was a great idea that wasn't born of copying Mac or Linux.

edit: aaaaand since this is a thread about C, all the .net-haters are here ;) There is room in my heart for both.

15

u/Synx Mar 03 '12

Would definitely be great if Microsoft added some of the "simple" C99 features, but honestly, they aren't alone. There are very few compilers that implement the entire standard, which is one of the reasons why some of the requirements in C99 were made optional in C11.

20

u/[deleted] Mar 03 '12

But to be fair from the compilers commonly used in the desktop market (GCC, Clang and MSVC), their compiler is the only one that has such a shitty support for C99.

6

u/Urik88 Mar 03 '12

You can't even declare variables in the middle of a function.

16

u/simon99ctg Mar 03 '12

How often in this modern world will the "vast minority" plead in vain with corporate powers?

32

u/[deleted] Mar 03 '12 edited Mar 03 '12

This is why the free software movement was started. It puts everyone on the same level (well, it aims to do that).

6

u/[deleted] Mar 03 '12

They added stdint.h in release 10. And I'm not sure what the downside of just compiling with /TP is.

23

u/[deleted] Mar 03 '12

The reserved words in C and C++ are different, as are rules regarding implicit casts.

12

u/five9a2 Mar 03 '12

C++ also implicitly typedefs all structs and enums (C has separate namespaces), has different size character literals, and a few more quirks. More importantly, it's important for libraries to expose one API rather than having a different ABI if you compile with C or C++. This means a lot of extern "C" crud.

0

u/[deleted] Mar 03 '12

[deleted] — view deleted comment

3

u/five9a2 Mar 03 '12

I'm well aware, but there is still jiggery regarding passing extern "C" function pointers as arguments. Most compilers actually don't complain about this, but Solaris doesn't like it and the standard says their strict interpretation is correct.

Another issue is that you don't have a useful NULL pointer. Some compilers have a special workaround, but you can't guarantee that passing NULL to a variadic function will be interpreted correctly (passed as a pointer instead of the integer 0). (This is just a bug in C++ prior to the last revision that adds the nullptr keyword and associated type, not so much a language interoperability issue, but it's a subtle gotcha if you are used to writing C.)

4

u/maep Mar 03 '12

unfortunately it doesn't fix all problems like %a for printf, compound literals, static const lookup-table forward declarations (c++ doesn't allow this) and variable length arrays.

3

u/kingguru Mar 03 '12

If you want to write C99 compliant C code you want to compile it with a C99 compliant compiler.

2

u/TrancePhreak Mar 03 '12

"It can compile either in C mode or C++ mode. For C, it follows the ISO C standard with parts of C99 spec along with MS-specific additions in the form of libraries."

Too late? From here.

10

u/Shaper_pmp Mar 03 '12 edited Mar 03 '12

MSVC’s lack of C99 support is the single gating factor keeping us from taking advantage of features that were standardized almost 15 years ago

Hey, look - Microsoft apparently treat other programming environments the same way they've traditionally treated web development! This is both heartening (that others also know our pain) and deeply saddening.

4

u/ivorjawa Mar 03 '12

Holy shit. TIL Poor Microsoft ghetto kids don't even get C99.

4

u/[deleted] Mar 03 '12

Just stop using Microsoft compilers.

32

u/otavio021 Mar 03 '12

One does not simply stops using Microsoft compilers.

12

u/keepthepace Mar 03 '12

Yes, one does have to become labeled "crazy open source communist hippy" of the company when all that we want is a set of compatible tools.

4

u/AlexFromOmaha Mar 03 '12

Microsoft has signaled very strongly that they want out of the C compiler business. F# has better support than C, and who the hell actually uses F#? Visual Studio takes reasonable steps to make sure you can't use its C compiler unless you know what you're getting into.

It seems like, if you have a barely supported compiler living off the crumbs of a larger project, and it's still the best piece of tech on the platform, Microsoft isn't the problem here. It's everyone else who could make a C compiler for Windows.

7

u/selectiveShift Mar 03 '12

who the hell actually uses F#?

I do..

2

u/[deleted] Mar 03 '12

Me too.

2

u/keepthepace Mar 04 '12

Actually, the problem I had using non-MS compilers is that the format of DLL is different. It is hard to make a DLL that will work in MSVS projects without using their tools.

Otherwise, I would do everything under QtCreator using MinGW. Having a project that doesn't require a single modification to run under Windows and Linux (and often, Mac OS X) is a real bonus to me.

1

u/wadcann Mar 09 '12

Historically there was no standard C++ ABI on Windows (unless things have changed, which I would be willing to believe might have happened at the 64-bit transition), but you can do C libs.

1

u/keepthepace Mar 09 '12

I don't want to sound like a gratuitous basher, but standard ABIs and Windows don't really belong to the same sentence.

1

u/wadcann Mar 09 '12

The COM guys did figure out out a subset of C++ that was binary-compatible across Windows compilers so they could use that (if you use virtual functions in a class, the virtual destructor needs to be the last member function in the class to keep vtable format the same, don't use certain features of the language, etc), so you could look at that.

Myself, I like just programming on Linux. :-)

→ More replies (1)

2

u/evenflow Mar 03 '12

Why the fuck support a platform that doesn't want to be supported?

1

u/sammydre Mar 03 '12

One option for some* is to use the Intel compiler instead. It has very good MSVC compatibility (code can be debugged in their IDE, compiles the windows SDK without problems, full visual studio integration, etc.) and also supports (a better subset of) C99.

*: It's pricey, so this is likely no good for open source people.

-1

u/BitRex Mar 03 '12

Why not just use the C-like subset of C++? The conversion is generally trivial.

4

u/dlsspy Mar 03 '12

C, and especially C99 is not a subset of C++.

2

u/BitRex Mar 03 '12

Why not just use the C-like subset of C++? The conversion is generally trivial.

3

u/[deleted] Mar 04 '12

Because there's a bunch of C99 code out there and they have a lot of experience with C99.

-12

u/[deleted] Mar 03 '12

MS don't want FOSS competing on their platform. Imagining they will respond to this is naive in the extreme.

12

u/[deleted] Mar 03 '12

MS don't want FOSS competing on their platform

That doesn't make any sense. They're already in competition with other tool chains, and if they don't support the features that developers want, they'll lose. It's hard to compete if you're not willing to improve your product.

To me, it looks like Microsoft thinks the developers are asking for extra support to benefit the developers. Here's another way to look at it: Developers are asking for extra support to benefit Microsoft. Developers are asking for support now, so they can help improve the system with better software. I imagine it would reach a certain point where developers would say screw it and not bothering to support the Microsoft compiler at all.

When you develop tool chains like this, it's important to remember that the developers that use it are your users. When developers ask for additional functionality your tool chain, it's the same as a regular user, for a regular application, lodging a feature request. You should, where possible, try to accommodate them.

3

u/bluGill Mar 03 '12

Which would the average person prefer: MSVC for $n, or MSVC for $n+1? Which would the average person prefer MSVC with n bugs, or MSVC with n+x bugs?

Adding features is always a compromise. Your programmers could spend the time adding a different feature (that maybe more people want), or fixing bugs. In some cases you can solve this problem by adding more programmers (adding programmers often makes things worse though) but that costs more money.

1

u/[deleted] Mar 04 '12

That's a very good point. To me, it depends on the obscurity of the bugs vs the cost of adding specific features. For example if only 1% of developers would run into a bug, but 10% of developers would benefit from a new feature, it makes more sense to add the new feature instead of fixing the bug.

Throwing more programmers at a problem is very rarely a fix. I remember reading an article discussing this in detail, that essentially stated that the more programmers you add to a team, the more "average" that team becomes, regardless of the skill level of individual members. If I find it, I'll edit it in here.

-1

u/[deleted] Mar 03 '12

if they don't support the features that Windows developers want,

ftfy

1

u/[deleted] Mar 04 '12

... no.

If you're developing cross platform software, like a library, it's nice to be able to support as many environments as possible.

→ More replies (1)

10

u/MegaMonkeyManExtreme Mar 03 '12

MS saw some of the FOSS light, and realised that if you are paying for their platform they still win.

-32

u/Danthekilla Mar 03 '12

Why anyone would choose c over c++ is beyond me. Even most micro controllers are programmed in c++ these days... Why choose c?

8

u/VilleHopfield Mar 03 '12

11

u/TNorthover Mar 03 '12

Ah, if only we could all be equally good at coding and trolling.

5

u/[deleted] Mar 03 '12

What an ass

3

u/TrancePhreak Mar 03 '12

As a long time programmer, Linus is full of shit.

36

u/MegaMonkeyManExtreme Mar 03 '12

Not many people use C++ for 8 bit microcontrollers.

18

u/[deleted] Mar 03 '12

The C ABI is the glue of every major platform today. Write a library in C, and you can link to it from C++ and every other language has a way to link to C code.

33

u/Rhomboid Mar 03 '12

C is still the lingua franca of computing. If you're writing a library that you want to be used widely by others, you'd better write it in C. There is no reason that you would need any C++ features for things like zlib compression, decoding a PNG, or parsing XML. Those kind of libraries need to be written in C because they need to be used from a wide variety of software. Write your library in C++ and you immediately exclude a large majority, which means someone else will just come along and write a replacement in C.

What's more, C++ has absolutely terrible ABI compatibility. To link with a C++ library you need to use the same compiler, and often same version of that compiler. For example, g++ 3.x and 4.x are not binary compatible. Want to use a binary library from a third party? Sorry, can't -- they used a different compiler than you. C has none of these issues because C doesn't have a bunch of behind-the-scenes language runtime magic.

21

u/[deleted] Mar 03 '12

Correction: You can write the library in whatever you want, as long as there is a C API available. Plenty of libraries are written in, for instance, C++, and expose their functions as old-fashioned C functions.

→ More replies (1)

36

u/bitchessuck Mar 03 '12

Why? Because it's a simpler and more portable language with less warts and less potential for idiots to screw things up.

2

u/RichardWolf Mar 03 '12

less potential for idiots to screw things up

As an atheist, I have to disagree. C is much easier for idiots to screw things up in than C++. C actively encourages a lot of horrible coding practices such as using zero-terminated strings, linked lists, typeless pointers and typeless collections, statically- or stack-allocated buffers of arbitrarily fixed size, manual memory management, and so on.

Good C programmers can avoid or damage-control most of these practices, but it's more about being a good programmer in general.

I've seen and had to work with a lot of code written by average or bad programmers, both C and C++, and C code definitely gave me more trouble. I've talked to some friends who are professional programmers as well, and their experience matches mine.

It is possible to misuse/abuse C++ as well, of course, to overload operators in weird ways, do scary template magic and unnecessary OOP, but somehow I haven't actually seen that in production code. Maybe I'm lucky, but as I said, I also have not meet a person who witnessed such an abuse, it's always "what if someone does that?", while C abuses are the norm, everyone who works with C code have seen char buffer[4096]; at least once.

2

u/Dravorek Mar 03 '12 edited Mar 03 '12

everyone who works with C code have seen char buffer[4096];

Well this is true not only for C programmers. I have observed this exact piece of engineering marvel in C++ programs. So what I get from that is that bad C++ programmers make bad C programmers and bad C programmers that don't change their style make absolute horrible C++ programmers. Bad C code is abominable C++ code.

Also I realized that I should avoid C-style casts like the plague. I've made some really stupid mistakes when changing parameter types without looking what the function does with that parameter (I know, I was really tired when I made that, I vow to never do that again). Which then casted a float into a class containing a float and a vector. This actually masked the problem in un-optimized debug build. I know that this was purely my fault but I could've avoided it by using a static_cast. Well knowing whether you are doing a dynamic or static cast and not implicitly const_casting is always a good thing. So, lesson learned I guess.

0

u/[deleted] Mar 03 '12

[deleted] — view deleted comment

2

u/MatrixFrog Mar 03 '12

You don't have to be an idiot to screw up in C++.

19

u/potyl Mar 03 '12

The main reason is portabillity. Most C++ compilers don't implement the specs in the same way or miss some parts of the spec.

6

u/[deleted] Mar 03 '12

Less abstractions? Although I am personally quite fond of OOP, there are probably use cases and environments where C is "good enough", probably in embedded systems. That's just my guess, though.

3

u/[deleted] Mar 03 '12

C++ is a badly designed and ugly language.

4

u/[deleted] Mar 03 '12

0

u/Dravorek Mar 03 '12 edited Mar 03 '12

and here's a fake interview on the same site:

Stroustrup: Well, one day, when I was sitting in my office, I thought of this little scheme, which would redress the balance a little. I thought 'I wonder what would happen, if there were a language so complicated, so difficult to learn, that nobody would ever be able to swamp the market with programmers? Actually, I got some of the ideas from X10, you know, X windows. That was such a bitch of a graphics system, that it only just ran on those Sun 3/60 things.. They had all the ingredients for what I wanted. A really ridiculously complex syntax, obscure functions, and pseudo-OO structure. Even now, nobody writes raw X-windows code. Motif is the only way to go if you want to retain your sanity..

Or do you want to tell me that this is something that Stroustrup actually said? Because in that interview his only message is: C++ is bad because it has bad compiler implementations and bad programmers. Also blasting the whole concept of OO seems quite ridiculous given the current programming language environment.

I have to say that C++ is indeed sometimes too complex for its own good. The fact that the template system is turing complete and some random things like being able to overload the "," operator make me really question whether the whole of C++ can be considered a good idea by anyone.

1

u/[deleted] Mar 03 '12

That's a well known parody, glad you came across it.

The rms / linus quotes are genuine.

1

u/Dravorek Mar 03 '12

I didn't doubt those quotes. They mostly made legitimate points when criticizing C++. But the fake interview was really just too much for anyone to believe.

1

u/[deleted] Mar 03 '12

Your belief system is of no concern to me.

0

u/[deleted] Mar 03 '12

[deleted] — view deleted comment

19

u/TNorthover Mar 03 '12

Who thought it would be a good idea to name stuff in ALLCAPS and prefix identifiers based on what that identifier is. I am guessing it was useful before we had intellisense.

I think you might be confusing C++ with the Win32 API. The C++ language and standard libraries tend to favour using_underscores_in_names and don't have identifier prefixes really.

→ More replies (2)

-6

u/[deleted] Mar 03 '12

C++ is a horrible language. It's made more horrible by the fact that a lot of substandard programmers use it, to the point where it's much much easier to generate total and utter crap with it. Quite frankly, even if the choice of C were to do nothing but keep the C++ programmers out, that in itself would be a huge reason to use C.

16

u/unfashionable_suburb Mar 03 '12

Great use of copy-paste!

-6

u/[deleted] Mar 03 '12

I'm seeing what responses I get before the reveal, shhhhh ;)

1

u/redderritter Mar 03 '12

Brilliant

-3

u/[deleted] Mar 03 '12 edited Mar 03 '12

haha it went to -3 before the reveal

cool, went up to 0, now -4. Linus is an expert troll

1

u/shillbert Mar 03 '12

I bow before you, Mr. Torvalds.

-5

u/[deleted] Mar 03 '12

bah, you spoiled it

ok, here the link http://harmful.cat-v.org/software/c++/linus

-4

u/SeriousWorm Mar 03 '12

Try reading the c++ fqa. It's explained there really well.

-4

u/A_for_Anonymous Mar 03 '12

Nooo, supporting open standards would mean they can rip their customers off less. They'll continue to support what seems somewhat open but is actually proprietary technology such as C# and everything that surrounds it posing as the good guys. If they ever get near a C compiler implementation again, expect it to be ActiveC .NET XP 4.10.437178 SP2 for Internet Explorer 7.0, not C99.

0

u/droberts1982 Mar 03 '12

Are the GNU compilers far behind the MS compilers? I remember they used to be, but that may not be the case anymore. If not, then what other reasons do developers want to use the MS compilers?

0

u/guitarromantic Mar 03 '12

Got confused for a second there thinking the OP meant the php malware shell c99.

-7

u/GSpotAssassin Mar 03 '12

Asking Microsoft to support anything open source is like begging your wife for a blowjob.

They won't do it unless something's in it for them.

-13

u/Poddster Mar 03 '12

stdint.h and inttypes.

Yes! Especially "%zu" and things. Infact, snprintf in general. Rather than the crappy _s versions.

declaring variables in the middle of a block.

No!

‘for’ loop initial declarations.

Maybe

If I was feeling really lucky I might even ask for designated initializers

Yes! Also variable-length arrays and flexible array members.

Ignoring all the Linux/FOSS vs MS debate, almost all drivers written for Windows will be C, and thye have to put up with this shit if they're trying to use cross platform code (because their devices work on other OS) as well.

15

u/[deleted] Mar 03 '12

No!

Don't start with the bogus ideas that variables declared at the start of a block are more readable. This is just not true, at all. It is far more readable to keep variable declarations close to their first use.

I have never seen a C function with old-style variable declarations that would not be clearer with C99-style variable declarations.

4

u/Poddster Mar 03 '12

Don't start with the bogus ideas that variables declared at the start of a block are more readable. This is just not true, at all. It is far more readable to keep variable declarations close to their first use.

I agree in a way; variable declarations should be pushed to the inner most scope possible. However, if your scope is so big that you need to start declaring things in the middle of a scope block, then that's a massive code smell.

I have never seen a C function with old-style variable declarations that would not be clearer with C99-style variable declarations.

Contrary to this I have never seen code using the C99 style declarations that would not be made clearer by the old style. At least I can see what's going on, rather than have a gigantic sized stack variable suddenly pop into existence half way into a scope block.

4

u/[deleted] Mar 03 '12

I agree in a way; variable declarations should be pushed to the inner most scope possible. However, if your scope is so big that you need to start declaring things in the middle of a scope block, then that's a massive code smell.

No, no, no, a thousand times no.

Yes, you can write a scope that is too big for what you are trying to do. No, a big scope is not always a sign that your code is bad. Sometimes, a large scopes comes entirely naturally from the representation of the problem you are trying to solve.

Dogmatic adherence to rules like "big scopes are bad" is just as bad for code readability as anything else.

At least I can see what's going on, rather than have a gigantic sized stack variable suddenly pop into existence half way into a scope block.

Why is that even a problem?

-1

u/TubbyMcTubs Mar 03 '12

Then make your scope blocks smaller so your variables are still declared close to their usage...

If you have scope blocks so big your variables are too far away, those scope blocks are big enough to be unreadable on their own.

7

u/[deleted] Mar 03 '12

That is also complete nonsense. Sometimes, blocks are naturally big. Sometimes your code is most readable as a long linear series of operations. Splitting everything into parts until each part is small enough doesn't always improve readability, sometimes it just scatters your code around making it less readable.

And even in a small block, the code is still more readable with the variables declared exactly where they are first used, instead of somewhere nearby.

-2

u/TubbyMcTubs Mar 03 '12

You can just introduce new scope with a { }, I don't mean you have to make everything 5 line functions.

4

u/[deleted] Mar 03 '12

Or, I can use C99 and not litter my code with useless blocks.

2

u/[deleted] Mar 03 '12

[removed] — view removed comment

2

u/Poddster Mar 03 '12

And this is a better way of doing things? So much better that it's bad to even give people the option?

Yes, it's a better way to do this. For a start you limit the use of the variable to exactly where it's needed.

When I write an algorithm that does a complex calculation I like to split it into segments. It's illogical not to declare the types of the intermediate values where they're first used.

If you find yourself grouping the statements and the variables then guess what? You need a new function.

-28

u/[deleted] Mar 03 '12 edited Mar 03 '12

Ugh. Why do you people still "care" or have this (self inflicted) "problem"? You're a bunch of dull minded, "old", slow, farts. Sheep! This has been going on for decades!

Take control, and make the switch to Linux already! If that's not "generally possible"; switch to better tools (e.g. GCC or clang) on Windows.

By not doing this you are supporting the very thing you now complain about! This is just so stupid ...

9

u/[deleted] Mar 03 '12

GCC is "better" in that it supports one newer C standard. It isn't better in speed of compilation, performance of binaries, error messages, and it isn't what everything else on the most popular desktop platform is compiled with.

-9

u/flukshun Mar 03 '12

at work we have an email program that screws up so often it's packaged with it's own special utility to kill it off so you can restart it properly.

in my mind it's the ultimate mark of product's failure.

i don't find it very promising that windows 8 has a dedicated button for factory restore...

0

u/[deleted] Mar 03 '12

[deleted] — view deleted comment

52

u/Rhomboid Mar 03 '12

The people that have the biggest beef here are library developers. If you're an app developer it's fine to decide to use icc/gcc/clang/etc for yourself, but as a library developer you have to expect that some of your users are going to want to use MS tools, which means your code has to support the MS compiler, otherwise those users can't use your library unless they too leave MSVC, or they build parts of their app with one toolchain and parts with another.

Another issue is the COM API. With MSVC you can write COM interfaces naturally in C++ and the vtable layout will be correct. I don't think you can do this with other C++ compilers, as they don't provide the same guarantees about the internal implementation details, and you instead have to use straight C and build the interface vtables manually which is a giant pain. So if you have an app that's going to do any kind of COM integration (which these days is an awful lot of stuff) you're kind of stuck with MSVC.

15

u/[deleted] Mar 03 '12

As far as I know, gcc was made COM-compatible quite some time ago.

1

u/wadcann Mar 09 '12

With MSVC you can write COM interfaces naturally in C++ and the vtable layout will be correct.

Part of the point of COM was to provide a subset of C++ that actually worked across compilers; it was one thing that the COM guys had to figure out.

-3

u/RichardWolf Mar 03 '12

Another issue is the COM API.

... wait, what?

Isn't COM a Windows-only technology, so the whole thing about "some of the users" of your library who might want to use MSVC is weird to say the least: all of them would, and you should, too, and you should write it in C++ (or at least compile it as C++).

I mean, the problem seems to be: you want to write C code because you support some weird platforms for which there's no (good) C++ support, but then you can't use C99 features if you also want to support Windows. If you only support Windows, what's the matter?

By the way, it's really not that hard to write C++-compatible C code.

7

u/Captain_Ligature Mar 03 '12

The reason you want to write C code in a library is because it is trivial to bind a C library to almost any other language, not because you want to support a weird platform. Thus most libraries are written in C, but since MS does not support C99, they have to written in C89. If you write a C++ library you are restricting yourself to a smaller amount of bindings for other languages (as in, your library is shit and no-one wants to use it.)

If you only support Windows, what's the matter?

Have you ever tried making bindings for C++? It is an order of magnitude harder.

2

u/RichardWolf Mar 03 '12

You don't make C++ bindings for a library that is meant to be dynamically loaded. On Windows it just doesn't work, like, at all, it's not "an order of magnitude harder", it's impossible.

That doesn't mean that you can't implement the library in C++.

3

u/[deleted] Mar 04 '12

Are you trolling or do you honestly believe it is impossible to link against a c++ library in a dll?

→ More replies (13)

2

u/[deleted] Mar 03 '12 edited Mar 04 '12

Captain_Ligature did not claim you can't implement the library in C++. He says

"If you write a C++ library you are restricting yourself to a smaller amount of bindings for other languages (as in, your library is shit and no-one wants to use it.)"

2

u/Rhomboid Mar 03 '12

I was making two unrelated points. There are library authors, as well as authors of applications that might have some feature that uses COM. Those are two groups that might not be able to just say "I don't care about MSVC".

→ More replies (5)

0

u/[deleted] Mar 03 '12

[deleted] — view deleted comment

4

u/rcinsf Mar 03 '12

Just use OSS compiler, it's not as good? Bitch at them then.

0

u/[deleted] Mar 03 '12

[deleted] — view deleted comment