tags:

views:

684

answers:

9

I would like to know what projects cannot be done in C.

I know programming can be quicker and more intuitive in other languages. But I would like to know what features are missing in C that would prevent a project from being completed well.

For example, very few web-frameworks exist in C.

+26  A: 

C, like many other languages, is Turing Complete.

So simple answer is: none.

However, C++ Template Meta Programming meets the same criterion, so "it is possible" is not a good criterion to choose tools.

Richard
I added the link to Wikipedia's 'Turing Completeness' article for completeness.
Outlaw Programmer
For any problem that cannot be (easily) solved in C but can be easily solved in another language, you can always write an interpreter for that other language in C and then use that language's program as data.
Adam Rosenfield
+16  A: 

The very first C compiler?

Sam Hasler
wasn't that written in C as well? A Bootstraping compiler?
cbrulak
I don't know about C specifically, but compilers are often written in their own language (even the first one).
EBGreen
@EBGreen: What do you compile the first C compiler written in C with? Not being snarky, I'm sincerely interested to know how that works.
Bill the Lizard
The first compile of the compiler is by hand based on the language grammar.
jms
The *very first* compiler for a language cannot be written in the language itself, since there is no compiler there to compile it ;)Often those have been written by hand or in a different language but after the first run you can use the generated compiler itself.
Kosi2801
looks like there's a few ways it could be done: http://en.wikipedia.org/wiki/Bootstrapping_(compilers)
Sam Hasler
If I recall my C history, the C compiler evolved incrementally from a B compiler.
Dana
The first C compiler was written in hand-crafted assembler. Only later did it get rewritten in C. Later came Stephen C. Johnson's PCC (Portable C Compiler) http://en.wikipedia.org/wiki/Portable_C_Compiler
dwc
@Bill - As I said I don't know about C specifically, but you could certainly hand compile the first compiler.
EBGreen
+1 for the interesting discussion this answer generated.
Ishmael
A: 

There is not a single algorithm that cannot be written with C.

Jess
That depends on your definition of algorithm.
Brian
even non-computable functions?
avgbody
+2  A: 

There are none.

Different languages give you different ways to say things. For some classes of problems a given language may be more expressive and/or concise. Are there projects that you should pick something aside from C? Yes, of course. But to say you can't do it well in C is misleading. It would be better to ask which language is the best choice for the problem at hand, and are the gains worth using something unfamiliar?

dwc
A: 

Depends on how much you want to invest (time/money/energy) to make it happen. Otherwise, I'd say there aren't any. It is just easier sometimes to use something else.

itsmatt
+3  A: 

Alright, here's one: you cannot write an x86 boot sector in C. This is one of those things that has to be written in ASM.

DrJokepu
And boot sector can also be written in C, if you have more than 512KiB of space to use and some smarter arch than x86 is.
Cheery
Cheery: I've meant x86 of course. I've updated my answer to reflect that. Thanks for pointing it out though.
DrJokepu
Actually, I'm not even sure I'd say that, although to do it in C, you would need a C run-time library and linker specific to the task.
James Curran
James: It's not just the library - you need a boot signature, you need to know that it's loaded to 0x7c00, you have 512 bytes max etc. That would be a very very special linker.
DrJokepu
Wait, you can't? Can't you just queue up the 512 bytes of space, and point the bios to that after setting up the registers for the int21h call to write a hard drive sector? All this can be done in C, and has been available since, well, forever. Check out free Turbo C 2.xx...
Adam Davis
I have it on good grounds that a certain hamburgler and pesto concoction has created an x86 boot sector in gcc.
Now, are we talking about a hard-disk bootstrap or a BIOS? For a HD, those are mostly (common) features of the sector writing utility. For BIOS, setting the load address is a standard feature of any linker (check link /? for the /BASE: option)
James Curran
No, we are talking about the code in the boot sector that is called by the BIOS and is responsible for loading the proper boot loader or the kernel from the disk and possibly setting up protected mode.
DrJokepu
+2  A: 

Anything can be done in virtually any language.

That said there is a level of practicality. As your system's complexity increases, you need better tools to manage it.

The problems are still solvable, but you start to need more people and much more effort in design. I'm not saying other languages don't benefit from design, I'm saying that the same level and attention to detail may not be required.

Since we programmers are Human (I am at least) we have troubles in one area or another. My biggest is memory. If I can visualize my code as objects, manipulating large modules in my head becomes easier, and my brain can handle larger projects.

Of course, it's even possible to write good OO code in C, the patterns were developed in C by manually managing dispatch tables (tables of pointers with some pointers updated to point to different methods), and this is true of all programming constructs from higher languages--they can be done in any language, but...

If you were to implement objects in C, every single class you wrote would have a large amount of boilerplate overhead. If you made some form of exception handling, you would expose more boilerplate.

Higher level languages abstract this boilerplate out of your code and into the system, simplifying what you have to think about and debug (a dispatch table in C could take a lot of debugging, but in C++ it isn't going to fail because the code generated by a working compiler is going to be bug-free and hidden, you never see it).

I guess I'd say that's the biggest (only?) difference between low level and higher level languages, how much boilerplate do you hide. In the latest batch of dynamic languages, they are really into hiding loop constructs within the language, so more things look like:

directory.forEachFile(print file.name); // Not any real language

In C, even if you isolated part of the looping inside a function, setting up the function pointers and stuff would still take lines of un-obvious code that is not solving part of your primary problem.

Bill K
A: 

OS kernel has been written in C and everything runs over it so you can write everything in C.

Boot sector that needs ASM :-) , I don't think you meant that.

Xolve
your logic is very, very flawed.
Adriano Varoli Piazza
Boot sectors do not /require/ ASM.
Geoffrey Chetwood
Most operating systems have parts that require assembler, too. Of course, you can "write" assembler in C with asm() statements...
Keith Smith
+7  A: 

A working solution to the halting problem

EvilTeach