Why do OS' have differ C implementations causing hell for apps to not be compatible, but no differ HTML/browser implementations reddit / BSD ---------------------------------------------------------------------- iamyounow · 2015-09-28 19:59 How come all the browsers/platforms adopt the HTML spec, and then have vendor stuff on the side, while all OS have differ C implementations and now all apps require major tweaking work for it to work on another OS. Does Apple have a differ C implementation than OpenBSD for example because of technical reasons or for control over users? I hate this whole situation. ---------------------------------------------------------------------- janizary · 2015-09-28 20:39 No. C is C, anything that is, "C," must be C. Different operating systems have different libraries which implement C in different ways, but must by definition act the same way. There are functions which are not part of C that are treated by various operating systems and library implementations as normal for them, but that does not make them a part of the standard which is C. OpenBSD has invented some things that are distinctly their own, as has GNU, as have various Unixen and Linux distributions. Those are not C, they could be considered regional dialects. There is nothing wrong with that, you just don't use them on every platform because they are not there, or you provide a copy when porting it to a new platform. Anything that has the ability to compile C, can compile C. That's just how it works. Those extra bits are not C, they are platform specific specialized solutions to problems developers have encountered with the C standard. ---------------------------------------------------------------------- giigu · 2015-09-28 20:46 Also, the implementation of Web technologies is nowhere *near* as consistent as you seem to believe. You could make an entire career out of keeping track of all the different ways browsers (mis)handle HTML/CSS/JS/HTTP. ---------------------------------------------------------------------- m1ss1ontomars2k4 · 2015-09-28 20:47 They don't. When it comes to pure C, the spec is fairly simple and not terribly complicated to implement. However, the C spec also doesn't define a LOT of things. Like, what's the size of `int`? `long`? It depends on OS. It depends on compiler. It depends on processor. It does not depend on anything in the C spec, except that `int` must be at least 16 bits at `long` must be at least 32, and that `long` must be at least the size of `int`. That's all the spec requires. This alone is already a huge source of headaches. But then `char` is almost universally 8 bits, regardless of platform. Now, there's also no boolean type. Should it be `int`? Should it be `char`? Does it matter? When? Perhaps most importantly of all, the C standard does not specify under what OSes, if any, the resulting compiled program must run. For example, if you have a multithreaded program, on UNIX-like OSes it almost certainly uses pthreads. But there's no pthreads on Windows. You have to use a wrapper library or switch APIs. Or what if your program uses graphics? On most OSes, OpenGL is supported. But if your app started on Windows you probably used DirectX instead, and now you have to port it. None of these things are part of the C standard. >no differ HTML/browser implementations If you think this is true, then I can be basically 100% certain you've never written any HTML in your life. Most websites have a lot of hacks for different browsers and different browser versions...and sometimes even for the same browser but on different OSes. ---------------------------------------------------------------------- Philluminati · 2015-09-28 21:10 Hello jquery. ---------------------------------------------------------------------- Philluminati · 2015-09-28 21:17 The browser market was a constant war with IE6 being the most functional at the time and shipped by default. Extensions galore as well as custom features. ActiveX and DRM. The reconciliation for it all is a side effect of IE6 growing old, new technologies being required, EU regulations on MS, Apples iPhone explosion. Silverlight, flash. JQuery and a desire for LAMP stacks. Nothing is consistent except the users want a standard, html5, and the browser companies sell that more. C never had such a troubled aggressive history. ---------------------------------------------------------------------- BumpitySnook · 2015-09-29 04:52 OP, remember when IE6 was the most popular web browser. For years and years. Despite blatantly ignoring or failing to follow many of the standards. :-) ---------------------------------------------------------------------- BumpitySnook · 2015-09-29 04:53 > except that int must be at least 16 bits at long must be at least 32 Must either of these? > But then char is almost universally 8 bits, regardless of platform. Char must be at least 8 bits, but it is at most one byte. > Now, there's also no boolean type. Should it be int? Should it be char? Does it matter? When? In C99 and C11, there is a boolean type. It matters mostly in that casting actually reduces all non-zero values to 1. (This isn't true of psuedo-booleans implemented with int/char.) ---------------------------------------------------------------------- m1ss1ontomars2k4 · 2015-09-29 05:58 >Must either of these? Well, that's what I remember, and that's what Wikipedia says. _Must_ it? Well, maybe, maybe not. I don't even think it really matters here. If the size is not defined by the standard, then obviously different compilers are going to treat it differently. ---------------------------------------------------------------------- iamyounow · 2015-09-29 14:32 So you are saying, if I was to grab a program that is for OSX, eg. Pixelmator and if its made in C, all I need is the libs they used, and if they are all in C, then it will compile easily on any other OS that has C? All these programs use C but the real meat and potatoes is the extra bits they use (libs that may not be in C or open source)? Im confused. ---------------------------------------------------------------------- iamyounow · 2015-09-29 14:37 > If you think this is true, then I can be basically 100% certain you've never written any HTML in your life. Most websites have a lot of hacks for different browsers and different browser versions...and sometimes even for the same browser but on different OSes. Your knee jerk reaction missed what I said about vendors when it comes to browsers. So I guess you think its as easy to get C programs running on different OS' eg FreeBSD to Windows compared to a webpage running on Firefox and then Opera? ---------------------------------------------------------------------- craftkiller · 2015-09-29 15:31 You're mostly correct, but there are some gotchas. For example, when you open a file from C, you generally aren't actually opening the file yourself. Instead, you are calling a C library function that interfaces with the kernel telling the kernel to open the file. For portability we would need all the operating systems to expose the same set of functions to interact with the kernel which is the point of POSIX. Also programs can execute other programs through the exec family of syscalls so in addition to the libraries you will need to make sure the expected programs are present and functioning as expected. Also there's a small chance that the primitive types differ. For example, I'm pretty sure "int" is defined as being the CPU's word size so if you wrote a program using "int" with a large value (say, 4 billion) then it might not behave appropriately on a system with a word size of 2 bytes. Oh also you need to make sure the other platform has the right services running too (like dbus) and accessible in the same way (probably through unix sockets). ---------------------------------------------------------------------- iamyounow · 2015-09-29 16:17 This helped me understand the subject more. Thanks bro. ---------------------------------------------------------------------- m1ss1ontomars2k4 · 2015-09-29 17:04 >Your knee jerk reaction missed what I said about vendors when it comes to browsers. That's because what you said, while true, is not the source of difficulty in making sure webpages are compatible with different browsers. What makes it difficult is all the stuff that _isn't_ supposed to be vendor-specific. >So I guess you think its as easy to get C programs running on different OS' eg FreeBSD to Windows compared to a webpage running on Firefox and then Opera? I didn't explicitly say that, mostly because it's not necessarily true. But that doesn't really matter, because my point is that webpages are not nearly as easy to keep compatible among browsers as you think they are, although it's for a different reason compared to C programs. HTML and CSS are not quite as well-understood or well-implemented as C compilers and C standard libraries: browsers have bugs much more frequently than C compilers do (at least for C compilers on their most basic, low-optimization settings). I mean, I don't even think there's a browser that claims to be fully HTML5 and CSS3-compliant yet. Acid3 wasn't passed by all major browsers until 3 or 4 years after it came out (IE strikes again--the other browsers got it in like a year or 2). Even if tomorrow all browser vendors introduced a 100% standards- compliant, mutually compatible browser, it still wouldn't help all the people out there who still have older versions of those browsers. Meanwhile, I think most C compilers these days are at least C89 compatible if not C99 compatible (Microsoft strikes again! they refuse to support C99, instead telling you to use C++ instead). The standard is the same across every platform, and every platform has implemented the standard...it's what's _not_ in the standard that kills compatibility. ---------------------------------------------------------------------- iamyounow · 2015-09-29 17:10 Ok thanks for clearing that up. So what is the future regarding how to fix this mess if you had to guess? ---------------------------------------------------------------------- gunnihinn · 2015-09-29 17:45 Software engineering obeys a strictly monotone increasing entropy law: nothing can ever be fixed, even locally. We're stuck with the mess. One day, enough people will get annoyed with any given mess that they'll implement higher-level paving to deal with it. Those people will all do it differently and in incompatible ways, leaving us with the next-generation mess. ---------------------------------------------------------------------- BumpitySnook · 2015-09-29 18:08 Ah, you seem to be totally correct. Sorry for whining. https://en.wikipedia.org/wiki/C_data_types Maybe I am remembering C89 rules and C99 specifies sizes more specifically. The main size requirement I remember is that each progressively larger size is at least as big as the next smaller (char <= short <= int <= long <= long long).