| helios (10126) | |||||||||
I wanted to reply in the thread, but it was archived, so here goes:
Also, the first phrase is completely backwards. It's portable code that often requires several versions. Code that's meant to work for a single platform needs a single version, while it's not always possible to use the same code for different platforms. For example, suppose you're writing a library to abstract file system operations. The function that creates a directory will need one version for Windows, another for POSIX, etc.
main(){}. C99 issues a warning.
Finally, https://developer.mozilla.org/en/C___Portability_Guide Not all the points in that guide will be relevant for everyone, but it's good nonetheless. Also, partly relevant to portability: http://www.jorgon.freeserve.co.uk/GoasmHelp/Unicode.htm | |||||||||
|
|
|||||||||
| chrisname (5896) | ||||||||
I think you've misunderstodd some of what he said.
I think he meant that if you write portable code for a cross-platform program, you only need to write one version (if you use conditional compilation inline with your code) as apposed to having a windows version, a Linux version, a Mac OS version, etc. of the whole program.
Compiler portability. | ||||||||
|
|
||||||||
| helios (10126) | |||||
Now, a program that isn't portable will have a single monolithic codebase. No different versions of anything and no conditional compilation (unless maybe the code has to be compiled by different compilers). Portable programs involve platform-specific code that grows in differentiation with complexity. What starts as checking sizeof and endianness soon becomes conditional compilation, multiple makefiles, and different toolkits being used in different platforms. I'm not saying that unportable code is better. I'm just saying that claiming portable code is simpler is absurd.
GCC has becomes rather touchy in recent years and likes to vomit warnings for nothing. How dares it tell me that (a && b || c)==((a && b) || c)? I didn't take Boolean algebra in high school for nothing! | |||||
|
|
|||||
| jsmith (5804) | |
|
[soapbox] Sorry, but portability is almost a joke. C/C++ can't even guarantee me the range of values an int can hold from machine to machine. When C was invented, programming was all about squeezing every ounce of speed out of the hardware (why? because C was invented to write an OS). "Portability" meant that my program would run "optimally" on any machine it was compiled on. That says nothing about whether it does the same thing on every machine it runs on. Speed isn't the concern any more. But while x++; increments x on any platform, it's hard to write any non-trivial C/C++ program (or any compiled language for that matter) such that it will compile and execute on multiple different architectures with, as helios mentions, writing some platform-specific code. Let's face it: unices have POSIX APIs, Windows has, well, Windows APIs. They're not the same. And GUIs... Unix has a plethora of GUIs/Window managers to choose from; Windows you have Windows. If you want to try to write an application that is "portable" and uses a GUI (most non-trivial apps these days), you're pretty much stuck with a cross-platform GUI toolkit like Qt. And just ask the guys at Trolltech about portability. Exactly how much platform-specific code have they written? Lots. Essentially, portability nowadays comes down to wrapping the kernel/OS in an abstraction layer. But that could be done in any compiled language. [/soapbox] | |
|
|
|
| computerquip (1892) | |
|
Its not C, the programming language,'s fault that different OSs decided to choose different API interfaces. Everything chooses to take a different path because it thinks its way is better (although I have no clue what X11 had in mind originally, but what it turned out to be was probably not that.). We can come up with a universal API for everything but what good does that do if nobody uses it? There's a reason why C/++ does that probably. I'm sure they didn't just say, "Hey, lets not make sense and do this to make people ask questions." There was original intent in it most likely with the large amount of planning placed in the language. Not everyone can get up and make a windowing system. It requires time, devotion, and knowledge ( and more often than not, wisdom). Because of this, we have no choice but to comply to those that take the time to implement what we need to program. What would you suggest? EDIT: It's completely possible in C to make a layer between the user and the OS that is the same on ALL OSes in the developers view. C++ is actually taking this to its advantage to implement things like std::thread. | |
|
Last edited on
|
|
| chrisname (5896) | |
|
@helios, I wasn't disagreeing with you. I was just suggesting that you misunderstood some of what he meant and took it the wrong way. I wasn't saying he was right. Edit: also, MSDOS doesn't accept forward slashes, only backward ones. | |
|
Last edited on
|
|
| helios (10126) | ||
| ||
|
|
||
| chrisname (5896) | |||
DOS is fun to play with. No hardware protection means you can basically write your own OS within it and then kick it out the way.
| |||
|
|
|||