Tell me more ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

It seems like most good books for learning C (like the K&R bible) teach you how to program C on a Linux environment. Like after compiling with the gcc compiler you are told to run "./a.out" and maybe use valgrind to test your program, which is only available on linux systems.

Why is this? Is linux supposed to be better suited for programs written in C compared to windows, and if yes then what are the advantages?

share|improve this question
 
C itself is independant from the operating system. The simple printf hello world program will compile and run on all platforms, be it on windows, linux, osx, cp/m, ... –  ott-- Sep 13 at 23:45
 
You can get MingW or CygWin for Windows. –  user16764 Sep 14 at 0:13
 
For learning a language the free Express versions of Visual Studio are far better than anything Linux has to offer. QTCreator is up there but not as good. –  James Sep 14 at 1:16
 
@James and qtcreator still needs a compiler to work (it's just an IDE) –  ratchet freak Sep 14 at 1:23

closed as primarily opinion-based by thorsten müller, gnat, GlenH7, MichaelT, BЈовић Sep 16 at 19:15

Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise.If this question can be reworded to fit the rules in the help center, please edit the question.

2 Answers

up vote 5 down vote accepted

C and Unix were created almost in parallel, both by K&R, and an early C was used to rewrite the Unix kernel for the PDP-11, sometime in 1973. Ever since that time, C and Unix (and its clones) have an almost symbiotic relationship.

This relationship has put C at the core of POSIX compliant operating systems, the C Standard Library (aka ANSI C / ISO C) is one of the standards of POSIX.1. Therefore, one big advantage of POSIX compliant systems over any other system when learning C is that a standard and up to date version of C is guaranteed to exist on the POSIX system.

From the perspective of a C book author this is quite important. They can target a large and popular family of operating systems with the same standard code examples and tools. Now, most GNU/Linux systems aren't fully POSIX compliant, however all major distributions satisfy at least POSIX.1 and include Standard C, via the GNU Compiler Collection.

This, of course, is also quite important for the learner. A POSIX compliant system provides a complete C development environment out of the box and thousands of C libraries to play with. For GNU/Linux systems the source code for these libraries is also available and you have the extra benefit of learning from it and reusing it.

Now, don't get me wrong, there's absolutely no reason why you can't learn C on a non POSIX system. It's just a lot easier to get started with it when everything you'd ever need is provided by the operating system and all you need to do is start coding.

Lastly, Linux is awesome. ;)

share|improve this answer

You said linux, but I'm going to assume you're referring to POSIX systems in general. I'll refer to them collectively as UNIX (for convenience, not correctness). UNIX and C are siblings in that they have mostly the same parents. It's also easier to learn about UNIX by learning C. So there's some synergy there, too, but ultimately the deciding factors should be:

  1. Why are you learning C? If you are learning C in order to write programs for Windows, then by all means, learn on Windows.
  2. What environment are you most comfortable in? If you aren't explicitly targeting UNIX environments, and you're much more comfortable on Windows, then trying to code C on UNIX will be trying to learn two things – you won't learn either as well.
share|improve this answer
 
I have a slight disagreement. Since C and Unix evolved together, I think that learning C and Unix together will result in learning both well. At least that is how it worked for me when I was learning (though admittedly I was learning Perl and Unix - back when Perl's nickname was, "The Cliff Notes of Unix"). –  btilly Sep 14 at 0:34
1  
I primarily use *nix with C, but I feel like I should add that Windows has much better organization of its API documentation, which may make learning about the OS API easier. –  Taylor Flores Sep 14 at 0:51

Not the answer you're looking for? Browse other questions tagged or ask your own question.