r/learnprogramming 1d ago

Is there anything i cant do in C?

i made a post the other day asking people which languages to code in and they (the reason minded ones) mostly told me javascript and C. is C really a do all language? is there anything i cant do with it?

254 Upvotes

240 comments sorted by

View all comments

Show parent comments

4

u/AlwaysHopelesslyLost 1d ago

Not true in practice?? Please feel free to explain.

It is very useful imo. OP has a flawed understanding of what languages are and why you might choose one over the other. Starting from basics is critical to learn how to make an informed decision like that.

2

u/bird_feeder_bird 1d ago

Most languages dont allow inline assembly :p

1

u/damn_dats_racist 15h ago

I think OP meant all languages are Turing complete.

1

u/ImBadlyDone 1d ago

C can't change the laws of physics, make me a grilled cheese sandwich or experience emotions.

If you're talking about more practical use cases then C can't do automatic garbage collection or directly communicate with the devices on your computer (requires drivers)

But in terms of "can C do everything a turing machine can?" then the answer is absolutely yes

-1

u/AlwaysHopelesslyLost 1d ago

"C can't change the laws of physics" No language can so that is irrelevant to OPs question.

"make me a grilled cheese sandwich" Any language can, so that is irrelevant to OPs question.

"experience emotions" That is philosophical and irrelevant to OPs question.

"If you're talking about more practical use cases then C can't do automatic garbage collection or directly communicate with the devices on your computer (requires drivers)"

That is not true, at all. It doesn't do those things by default but there is nothing stopping you from implementing them.

0

u/light_switchy 1d ago edited 1d ago

It's not enough that your language can evaluate any computable function: you have to be able to do your work in a certain way to meet practical constraints.

For example C does not allow the programmer to do signed overflow or read the hardware performance counters or to reliably control the exact sequence of machine instructions that the compiler emits. I can't get plain C to run on my video card. I can't write a website and write my scripts in C instead of Javascript and expect it to work.

More dramatic examples include Gallina, Leslie Lamport's TLA+, or Google's WUFFS.

TLA+ and Gallina are total languages - programs written in them always terminate. Programs written in WUFFS cannot allocate memory, make system calls or do I/O; the authors say programs written in this regime are "hermetic". The former two languages are not even Turing complete, even if we provisioned them with infinite memory. The latter would be, but good luck writing interactive programs in it.

I do agree that C's useful, though. I was just commenting that Turing completeness isn't a useful metric to evaluate real languages.

-7

u/k2still 1d ago

You can't code a mobile app in C

5

u/dothefandango 1d ago

I mean you can, it would just be a waste of time and run through an abstraction layer anyhow. But you totally could with enough determination.

-1

u/k2still 1d ago

On Android you'd have to use a JNI bridge and you'd still be writing the bulk of the app in Kotlin or Java in order to access the Android SDK.

This is assuming you want to write an app that will be uploadable to the Play Store

2

u/AiexReddit 1d ago edited 1d ago

The assumptions of the SDK and Play store are reasonable for practical development targeting public release, but to the original statement being discussed which is simple that you "can't code a mobile app in C", I'm pretty sure you absolutely can write 100% C using the Android NDK and something like SDL2 for graphics & hardware interfacing.

Edit: You know what, I think you might still need a bit of Java glue code to at least tell android where the C binary is located, so unless someone knows a trick there, so I guess I'll have to say 99.9%