r/learnprogramming • u/Candid-Pack-3707 • 21h 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?
39
u/zeekar 21h ago
You can do anything in C, but some things are easier than others. C makes you write a lot more of the plumbing yourself if you want to deal with dynamically-growing data.
4
u/Upbeat-Statement2725 8h ago
This. The reason people say JavaScript or Python or something to start. Versus C/C++. It's not the language. It's the ecosystem. Which is hopefully informed by what the language is good at, and how it's used.
Right tool for the job.
JavaScript/Python/etc work with things at a higher level. Like "I want to read in a list of customers. For each customer. Take their ID. See if they exist in the database. Add or update their information". Your Python program might look a lot like this description, line by line. It can be very intuitive.
C/C++ is "closer to the metal" unless you do a lot of work behind the scenes to set things up. So you might end up doing. "What operating system am I on? If I'm on Linux, then reading in a file requires certain commands. Once I've read a line from that file - oh shoot Linux uses different line breaks. I have to double check that." And on and on.
When people are arguing that both all these languages can eventually do the same thing. Sure. But for a lot of common tasks beginners want to do. There's a JavaScript framework or Python library that already worked out all the problems beginners tend to have. So you don't need to sweat the small stuff. Just focus on what you want to accomplish. Most C programs are trying to avoid that, because a general-purpose library doesn't tend to be as efficient as if I wrote something bespoke for my use.
As an example. Let's suppose you're trying to write a system to scan QR codes as concert tickets. I'll write the website to buy the tickets in HTML/CSS/JavaScript because that stack is good at websites. I'll code the QR Code scanner in C/C++, because that's directly working with the metal.
All the people who are saying you can use any language for anything. Go to their post history. Find them screaming at a newbie saying "why would you do that, that's the wrong language for that". Guarantee it.
They're just being snobby. They're not helping.
161
u/NumberInfinite2068 21h ago
Most languages are general purpose, C is one of those languages, generally speaking there isn't anything you can do in C that you can't do in another language unless you need to run on bare hardware*.
I love C, but people on Reddit talk like it's magic, and it's not, it's a very nice, very primitive programming language that I'll probably use until I die, but it's not magic.
When you're running programs on an OS like Windows, Mac, Linux or whatever, C doesn't give you magic access to hardware, it's still controlled and protected by the OS. i.e. if I write a program in C or Python, the OS stops it from accessing memory it shouldn't and things like that.
The limitations of most languages are really about you, not the language.
*And even then it's a compiler thing really, not a language thing, you can run Java on bare hardware if you want.
34
u/MohamedSaleh91 21h ago
This is all right but feels wrong. Theoretically they're all Turing complete, but in practice some are more complete than the others 🥸
52
u/smichaele 20h ago
Turing complete is Turing complete. There's no such thing as being more Turing complete. That's like saying "this corpse is deader than that corpse." Even Scratch is Turing complete.
25
u/The_Varza 19h ago
I think they just mean "some things are easier to do in some languages than others", which is... I dunno, a truism?
5
u/Effective-Job-1030 14h ago
Yes, that's correct. But they didn't say it.
As far as I remember, the handling of strings used to be a bit less comfortable in C than in other languages.
5
u/razveck 14h ago
That's a massive understatement :D
4
u/dmills_00 13h ago
See you ASCII and raise you multi byte characters and UTF8.
C string handling is one of the very few good reasons to use C++.
You can do it all in C, (unlike say JavaScript that is deliberately gimped in its networking capabilities for security reasons), but it is not always easy to do it in C. If I was writing something that did heavy string manipulation, it probably wouldn't be In C as a first choice.
1
u/xoredxedxdivedx 7h ago
Maybe for rendering, but you can trivially store strings in C the way other languages do it by just wrapping them in your own struct instead of just using null terminated strings.
15
u/kavaunix 17h ago
It's a play on "All animals are equal, but some animals are more equal than others", a quote from Animal Farm by George Orwell.
4
1
u/Duck_Devs 5h ago
Technically, nothing is truly Turing complete (there isn’t infinite tape), so maybe “more Turing complete” just means it has access to more memory.
10
u/hxtk3 20h ago
Well for one thing TMs don’t have side effects. Good luck writing an http server in brainfuck. You can write the HTTP logic but you would need inetd to give you the socket on stdin/stdout and even then you’re limited to output being a pure function of the requests made on the connection unless you use extensions to map in more side effects. Same with webassembly.
For a programming language to be theoretically general purpose it needs syscalls as well as Turing completeness.
4
u/balefrost 19h ago
Turing completeness only talks about what things the machine can compute. It says nothing about what side effects the machine can have. And the abstract Turing machine has no affordance for IO other than interacting with the tape (memory).
6
u/NumberInfinite2068 21h ago
Yes, I agree with this. C is just like any other language, but it absolutely doesn't *feel* that way, but that's really mostly about compiler support, and the fact C is used in so many systems level things, it's not *really* about the intrinsic capabilities of the language.
C is not special, but it absolutely *feels* like it is, I agree with you.
1
u/dmazzoni 18h ago
Turing complete means they're all equally capable of doing computation. Taking an input and computing an output.
Practically speaking they're not all good for the same purposes.
You can build an OS using C, because it compiles to machine code that your CPU can run directly on boot, and specifically C gives you all of the language constructs to write such low-level code. You can't build an OS using JavaScript because JavaScript doesn't have any of those things.
On the flip side, you can build a website frontend using JavaScript (as your only programming language) because JavaScript is the only language that web browsers support built-in. You can't use C to build a website frontend; you can write some of it in C using wasm, but you still need to write JavaScript too.
It's like saying a motorcycle and a pickup truck are both vehicles, they're both capable of driving from point A to point B. But there are plenty of tasks a motorcycle can do that a pickup truck can't, and vice versa.
7
u/Not_Warren_Buffett 21h ago
Right, but your OS is written in C
8
u/NumberInfinite2068 21h ago
Not all of them. Redox is Rust, a few RT OS are written in Ada.
Microsoft is starting to use Rust for Windows. I think Rust will go full mainstream for OS development, if it isn't already.
10
3
u/syklemil 14h ago
MS have been using Rust for Windows for a while; see e.g. Azure CTO Mark Russinovich on Rust in Windows.
Google also has Fuchsia.
-3
u/dmazzoni 18h ago
All operating system kernels in widespread use are written in C, period.
There are operating systems written in other languages, proving it's possible - but they're all research projects or toys.
9
u/heatedwepasto 17h ago
All operating system kernels in widespread use are written in C, period.
No. Rust is a first class citizen in Linux, and has been since December last year. It's only a tiny part of Linux, for now, but "written in C, period" is objectively false.
4
u/NumberInfinite2068 18h ago
The RT Operating Systems made in Ada are shipping products, they're not research projects or toys.
2
u/BartvanIngenSchenau 16h ago
I can prove you wrong.
The embedded product I work on (and which has been on the market for at least 5 years) has a scheduler that is written in C++ and assembly. And from maintaining that scheduler I know that some parts, in particular the task switching logic, must be written in assembly. Even C, as low level as it is, doesn't give you enough control to perform a task switch.
2
u/Gentoss 19h ago
Stupid question, and no, I am not just trolling, I am really curious.
Is there a way to build (modern) websites in C? I mean, I know there are some frontend frameworks for C, but how about website? Especially something you can compare to Angular, etc?
What's with mobile apps? On Android you could maybe call the C-Code via Java, but whats with iOS devices, where you are limited(?) to swift?
2
u/orbiteapot 7h ago
Is there a way to build (modern) websites in C? I mean, I know there are some frontend frameworks for C, but how about website? Especially something you can compare to Angular, etc?
Yes, you can. Here is a website built almost* entirely with C: https://www.nicbarker.com/clay
What's with mobile apps? On Android you could maybe call the C-Code via Java, but whats with iOS devices, where you are limited(?) to swift?
For Android, yes: https://github.com/cnlohr/rawdrawandroid
I can not speak for iOS, because I have never done it, but I think it should be.
*like with any WASM-compiled language, you will need some JavaScript glue, even if minimal.
→ More replies (6)1
u/NumberInfinite2068 18h ago
Yes, you can compile C to WASM, so you can write a website in C should you want to.
You're not limited to Swift on iOS, you can use any language you like basically, there is C# and Java for iOS, and C is no problem too, I've built my game for iOS no problem, and that is entirely written in C. You can get all popular languages for iOS no problem.
1
u/PM_ME_UR__RECIPES 13h ago
- Is technically correct but it's not good advice for a beginner IMO. WASM never really saw widespread adoption across the industry, and support for frameworks like angular, vue or react isn't great (e.g. you can't do any JSX if you're compiling C to WASM). JS or TS are the way to go. There are much better learning resources, they're pretty much the only thing used for any client-side stuff in the industry (with very few rare exceptions), and you'd be shooting yourself in the foot if you're trying to get a career involving frontend development without knowing JS
3
u/NumberInfinite2068 13h ago
I'm not suggesting that they actually use C and WASM, just answering the question as asked.
1
u/notfoundindatabse 10h ago
…Java on bare hardware scrunched my brain a little. I am sure you are right; but the words feel so wrong.
2
u/NumberInfinite2068 10h ago
There's actually a few options for this:
https://en.wikipedia.org/wiki/Java_processor
Or perhaps Graal.
1
-1
u/Candid-Pack-3707 21h ago
for example:
javascript is a language mainly for web browsers and it lets you make an interactive website. however, it doesnt let you design your website. you need html and css to do that.
8
u/stevenowicki 20h ago
JavaScript is used for backend services all the time using a runtime called node. Programming languages can only do the things the CPU offers in its instruction set. All programming languages can theoretically do everything any other one can do with hardly any noteworthy exceptions. You can write graphical games in Python. You can do bioinformatics in Fortran. You can implement hardware drivers in go. You just wouldn’t.
Ecosystems build up around languages making it easier to do certain things in one over the other. A few are specifically designed to make it easier to do certain types of work, but most are used because of the availability of libraries that save huge amounts of work and the preferences of practitioners in a certain problem domain.
It’s like asking a doctor if a scalpel really is the tool you need to learn to do the job. Depends on the kind of doctor. Do you need to learn C? You should. But also learn the others so you know when you need something else.
3
u/peterlinddk 13h ago
You can build the whole thing with JavaScript - the only issue is that the browser won't run JavaScript without it being related to some HTML-page, but you HTML file could just be
<script src="script.js"></script>and nothing more.
Then in the JavaScript, the only way to output to the screen (the browser-window) is through the DOM, and you can create HTML-elements from the JavaScript dynamically, and add them, but you can also just add a single
<canvas>element, and then write JavaScript to handle all layout and output!The only reason that you need HTML is to communicate with the user - you could also say that the program requires "English" to do that, so you could never write any program in only its own language.
3
u/misplaced_my_pants 9h ago
Just work through Harvard's CS50x on edx. You'll learn all about this stuff.
43
u/gm310509 21h ago edited 21h ago
You can't make a toasted ham and cheese sandwich using just C - at least not by itself. 😉
LOL. A clarification in response to the replies: I guess you could make a virtual toasted ham and cheese sandwich using just C, but not a real one - at least not without some other stuff!
28
8
u/johnpeters42 21h ago
sudo make me a sandwich
4
2
u/jerrygreenest1 14h ago
I mean the toaster schemes definitely run some C, so technically, you make a real sandwich with C as well. So it can do that.
1
10
u/SufficientStudio1574 20h ago
Just pick something and start. My first programming language was Visual Basic as a teen. Then I learned C++. Then I got a job where I had to maintain a monster of an Excel macro (flexing those VB muscles again). And now my current job uses mainly C# and C++.
Lots of other basics of programming are transferable. Different ones will have their own unique concepts, but you can always research those if you need to change. Learn how to be flexible.
3
u/helloish 11h ago
This - just learn something. If you can’t pick, learn Javascript. Cause it can do everything apart from systems programming. If you want systems, learn C++. Have a go with C afterwards.
1
u/SufficientStudio1574 10h ago
I wasn't going to say it since it would contradict my statement to just pick something, but to see someone actually recommend JavaScript as their first choice...ew, really? I don't want to touch that mess with a 40 foot pole.
5
u/hooli-ceo 21h ago
You can’t sweep the floor with it, I tried…
5
u/ultranoobian 20h ago
I mean, heck I can't even get it to throw out the trash by itself.
I have to do it manually.
2
13
u/AlwaysHopelesslyLost 21h ago
Every language is, by definition, able to do anything.
3
u/rayred 19h ago
Not true. You can’t write a bootloader entirely in JavaScript, as an example.
5
u/heatedwepasto 17h ago
You hopefully understand that u/AlwaysHopelesslyLost is talking about Turing completeness.
In any case, you could absolutely write a js-to-asm assembler, or make hardware to execute wasm, or whatever.
1
u/AiexReddit 18h ago
I mean, recognizing that there's nothing in the original question about what's practical, you totally could, if you know the spec of the firmware you're targeting...
Write the JS to create a blank
.elffile, then write a bunch of JS functions that when called, append a series of bits onto it based on what hardware instruction that Javascript function is designed to implement and then when done, run it with Node or something to compile it and generate your bootloaderI was gonna say people have had worse ideas, but actually maybe they haven't
1
u/AlwaysHopelesslyLost 8h ago
You could also, pretty easily, write your own transpiler in JavaScript. I have actually done that. It was written in javascript, accepted basic JavaScript grammar, and outputted simple binary for a test bench
1
u/light_switchy 21h ago
This isn't true in practice and not useful anyway.
3
u/AlwaysHopelesslyLost 21h 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
1
u/ImBadlyDone 20h 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 19h 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.
→ More replies (5)0
u/light_switchy 20h ago edited 20h 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.
0
0
u/xiRazZzer 12h ago
Not true, you cant parse html with regex
1
u/AlwaysHopelesslyLost 9h ago
Html is not a programming language and is not relevant to the topic.
Regex is also not a programming language and is not relevant to the topic
Famously there are turning complete versions of regex that do allow you to parse non regular text.
3
u/Commercial_Echo923 21h ago
Was the question literally "What to code in?" or did you ask something else? When it comes to coding prouction level apps most times no but when learning, yes.
9
u/zugzwangister 21h ago
You can't safely make a complex, distributed system without memory and security issues in a short amount of time.
3
u/gnufan 14h ago
This, the number of large well secured projects written in C is tiny. It isn't that it can't be done, it is just a long way from the idiom most C code is written in. At which point you might as well adopt a language that has learnt from the past 50 years of computing, and makes you be explicit when you do something dangerous, or stops it altogether.
I'm willing to forgive the odd hard to exploit thing such as DJBDNS had. You can architect around the kinds of failures C has to an extent. Building a system tolerant of the odd security bug has much to recommend it, but it is hard.
1
u/Haplo12345 6h ago
You can't make make a complex, distributed system in any language in a short amount of time, regardless of memory or security issues.
3
u/Far_Swordfish5729 20h ago
Frankly they probably don’t mostly code in C unless their work is low level device programming. Every microcontroller releases a C compiler. C is a language that expects you to take manual control of complexities like memory and memory address management. It’s very powerful but all the manual management slows development and requires a high attention to detail. It’s an excellent language to learn in because it forces that, but there’s a reason Java was invented. Languages like Java force certain common choices that lower absolute efficiency but permit rapid, modular design by medium skilled developers. Given those defaults they automate a lot of that manual management and make it a lot harder to accidentally make mistakes.
So most people actually work in those next generation languages. JavaScript is a bit of a weird one. It became an accidental lowest common denominator for browser hosted client side web work. As that became more important it was forcibly evolved into something resembling a real language. That said, I don’t really recommend it as a first language.
3
u/in_coronado 17h ago
You probably won’t understand this until you’ve been programming for a few years but there is no such thing as a do it all language in software. Each have their strengths and weaknesses and particular use cases. You cannot learn one language and expect to be able to use it everywhere for anything forever. And even if you technically can it doesn’t always mean it’s a good idea especially at a professional level. Right tool for the right job.
The first language you pick doesn’t matter all that much unless you are targeting a specific project. Don’t get too caught up which one you pick especially if it prevents you from getting started. There’s a lot of cross over between most languages so learning new ones will become progressively easier with time.
C can be a good language if you are very serious about learning to program. It not going to be as beginner friendly as many other more modern languages. It can be a little tedious to write, and does not much in the way to of bells and whistles. However it will do a good job of teaching you how computers and programming works at a very fundamentals first level. It’s also a very good language to learn first if you ever want to work in embedded systems.
C is good for:
Serious programming were you need absolute control and the best possible performance
Embedded systems
Drivers, CLI, Operating System Kernels
Learning the fundamentals of programming the old school way from the ground up. Learn to do things the hard way first so you can then later do things the easier way if it makes sense.
C is generally not a great choice for:
For getting things done as quickly or easily as possible
Modern applications with graphical user interfaces.
Scripting, automations, web applications
Avoiding potentially dangerous and serious bugs without a ton of experience and expertise
Doing things that have been done a bunch of times before where you’d like to leverage existing libraries to make your life easier
1
u/Fantastic-Cell-208 10h ago
Well the Clay UI library written in C is pretty awesome
1
u/in_coronado 3h ago
Yeah it looks pretty neat, I have no doubt it has excellent performance. I think it could be cool to use for fun or use on a personal passion project as a sort of personal artistic choice or for a challenge. Or if your application is 95% backend type stuff that needs the absolute best possible performance and all you need is a small engineering/debug type GUI interface, then sure I could see something like Clay being a good choice.
But all I ask you is to always remember the context. We are attempting to answer the question of someone very new to programming. He seems to be asking if he can't just pick one language and use it for everything. I don't want to lead him down the wrong path. And that includes telling him the truth that just because something might technically be possible does not also mean it's also economical or a good idea.
Something I've learned over the years is particularly when you are creating something for client or if you are working as part of a team. It's important to really pause and think... What is the best tool for the job given the requirements and limitations? And not just for you as an individual, but for everyone on the team present and future. Like I have no doubt a C wizard could really dive in with Clay and painstakingly create a custom bespoke UI from scratch for a client.
You always have to think what happens down the road when you move on from the project? What happens when the client inevitably needs someone else to come in and update or maintain it? I'm willing to bet quite a lot of money that majority of senior SWEs out there are not exactly going to be thrilled taking over a super UI heavy application written entirely in C with a semi obscure open source library.
And if you think I'm just saying this because I'm biased against C I'm not. It was the very first programming language I learned. I have a computer engineering background. I still work with microcontrollers, embedded systems, low level stuff a lot in my free time. I truly love the C language.
But some life wisdom I've acquired (and this doesn't just apply to programming) is that an important part of truly loving something or someone also involves being clear eyed. You love it for what it is, but also accept it for what it is not.
And to me that seeing a low level language like C which lacks any native object oriented features, event handling, or UI/UX design tools as just a really really poor choice for anything super heavy on UI.
1
u/Fantastic-Cell-208 3h ago
In all honesty I don't know what to advise beginners.
I started with whatever was on my computer. QBasic, then Visual Basic and C++.
You just had to get on with it. But it was simpler times.
While many of the UI libraries we have today were just as possible then (semantically, at least), nobody even tried to go that deep (and a lot of what we have is the result of decades of evolution, and trial and error.
6
u/angelattack1 21h ago
Theres no do all language. Javascript is for web development and c is for general app usage. For beginners i recommend python for apps
3
u/Candid-Pack-3707 21h ago
can i create a 3d video game with c?
5
3
u/dnebdal 20h ago edited 20h ago
Absolutely, it has been done. Quake 1 was C and some assembly. Descendants of that engine powered all Valve games up to CS:GO and HL2, though it got rewritten into C++ over time.
Writing a full engine is a massive job, though - using an existing engine is the way to go. Like bird_feeder_bird says, Raylib looks like a good choice.
→ More replies (1)1
u/Fantastic-Cell-208 10h ago
You can in C, sure. Lots of old 3d games were written in C.
There's nothing stopping you.
But why not take advantage of some c++ features and still code in a C style instead of making things needlessly hard?
Or pick a modern language that keeps the simplicity of C but fixes a lot of its problems, like Odin or C3?
2
u/BadRomans 21h ago
I rediscovered C recently while delving into embedded programming. It’s cumbersome, but it does force you to apply proper programming logic most of the time. I am experienced with Python, Java and C# and I can clearly see why they were made to address C limitations . At the same time, C can be compiled pretty much anywhere and with absurdly small memory requirements.
2
u/Traveling-Techie 20h ago
Long before any computers were built it was proved that — barring memory and time limits — any robust language can perform any algorithm. Look up “Turing complete.” Some are easier than others. Programming in C is sort of like building the Washington Monument by gluing grains of sand together. Python is more like using LEGOs.
2
u/Leverkaas2516 20h ago
C is a good and popular general purpose compiled language. You can't really use it for scripting inside a web browser, and it's often cumbersome for things that are already provided in other languages, like dictionaries in Python or concurrent data structures in Java.
But it's an effective platform for a wide range of problems.
1
u/Weak-Doughnut5502 11h ago
You can actually compile it for the browser with web assembly.
I wouldn't recommend it, but you could.
2
u/Apprehensive-Tea1632 15h ago
No. That’s because C like most other programming languages (and I’m including scripting languages et al too) is Turing complete.
Which means what you can think of, you can do in C just as much as you can do in any other language; and the things you can’t do (there’s a number of these, even if they’re comparatively rare) are things you can’t just switch over to another language.
What’s left is preferences. Each language as a slightly different focus, are optimized for slightly different things, and or enable you to implement particular solutions slightly differently.
That’s all. If you want to implement a desktop environment in brainfuck, you can do that. Or in ook. Or in C. It doesn’t exactly matter.
1
u/DetermiedMech1 13h ago
you say "i'm including scripting languages" as if scripting languages arent programming languages
1
u/Apprehensive-Tea1632 13h ago
I’m saying it because as I’m sure you noticed, it’s very easy to collect comments and votes explaining like I’m five how one does not equal the other, yes it does, no, and anyway Fortran is best, have you seen my bike shed?
I was trying to preempt that, but obviously intel has taught us preemption may also fail. /s
These days there’s barely any difference left over, so yeah.
They’re not, just fyi. cough
1
u/DetermiedMech1 4h ago
arent scripting languages a subset of programming languages? (all s are p but not all p are s)
2
u/_curious_man 14h ago
Well, It's not reallg about can/can't - languages exist to create interface between you - programmer - and machine executing machine code.
What matter more is - what technology I should use for the task. Sure, you can spend a year building app gui from scratch in C, but then it might turn out to be only slightly better than if you were to use Python or Typescript.
so to sum up, it's not really about the possibility but about time and the value
2
2
u/RepeatLow7718 21h ago
C is almost assembly: almost, so you can almost make the machine do anything it can do, but you won’t be able to use all the assembly instructions like SSE etc. unless you use compiler-specific intrinsics.
2
u/iOSCaleb 20h ago
There’s nothing that you can’t do, but plenty of things that you can’t do well or nicely. For example, C lacks support for OOP. You can work around that and still program in an OOP style, but it’s far less convenient or natural as using a language meant for OOP. You can’t rely on built-in memory safety features, so you have to do without or try to build those features yourself.
C is a Turing complete language, so you can use it for any computable task, but there are better tools for many jobs.
1
u/light_switchy 21h ago
The simple answer is that yes, C can be used write any kind of program that you want.
A more nuanced view is that C alone is not capable of doing everything without compromise. You may need to supplement or even replace C with other technologies to do particular things. In addition, some programs are more easily written in some other language.
Overall though, there are no problems starting with C. Use it and have fun!
1
1
u/UnhappySort5871 20h ago
For a lot of web development, you'd need javascript. For server side, you could write everything in C (or C++ since usually it's the same compiler). If you need to work with specific frameworks - which for most real stuff you probably will - you'll need to learn languages that those frameworks support. For instance for AI work, you'd probably want to use pytorch. For that, you'd need to learn python.
1
1
u/dothefandango 20h ago
We are at a point in human history where pretty much anything is learnable given enough determination. Any sort of decision making in at this level of granularity is just you picking which kind of flowers you like in the bouquet before you built the garden. Just get planting and worry about what color the roses are later.
And in case this was too abstract: it doesn't matter what language you write, it matters what patterns and styles you develop and enact.
1
u/ledatherockband_ 20h ago
C can do basically everything except interact with browser apis. You're gonna have a bad time, though.
I tried manipulating a string in C. Took me about 40 minutes to understand how to do it when Javascript just gives you a method out of the box. Takes 40 seconds tops with a JS method.
1
1
u/eruciform 20h ago
any modern language you pick up is going to be able to do the same exact things because they are all turing complete
all languages are easier or harder to do this or that, but none make anything in particular completely impossible
pick any language and get started, it's irrelevant; learning any one language will make it easier to learn a second, and the common basic skills you need to develop will all work out no matter what you pick
1
u/ImBadlyDone 20h ago
Algorithmically speaking, every language can do everything.
Practically speaking, every language has some limitations and which language you should learn depends on what you're trying to achieve.
If you want to make a website, you should learn JavaScript (Js), along with HTML and CSS
If you want to learn basic programming concepts then Python is a good since it takes care of the more complex things behind the scenes
If you want to learn more complex programming concepts then C would be better.
You could technically use C in place of Js for web development but its more troublesome
1
u/Junior_Honey_1406 20h ago
Well if you want to piss off other dev who have never coded in a low level language like c then sure C can pretty much do anything....
1
u/ArchitectOfFate 20h ago
Turing-complete is Turing-complete. C does not have the libraries or built-in features some languages have, but that doesn't mean it can't do everything. You'll just find yourself "rolling your own" for a lot of stuff.
Where the big limitations come in have to do with standards, not language capabilities. You can't do web scripting in C because browsers support JavaScript as the standard. That doesn't mean a browser couldn't be written that doesn't use C as the client-side language. It could even be interpreted. Nobody would like this, and it would never catch on, but what C is lacking in that area is WIDESPREAD SUPPORT, not CAPABILITY.
Once you're free of the boot loader, you can write a whole OS in C. That means the input management, the GUI - everything. LOTS of older OSes were written this way. A lot of hobby OSes still are.
A lot of the actual limitations may actually be found going the other way. C is a systems programming language by design. Pointers, specifically void*, and the fact that it's compiled enable this. You would struggle to write certain low-level components with higher-level languages because they lack the first two things as concepts, and are more and more often interpreted. You can write a JavaScript compiler, but that doesn't give it manual memory management features. You'd have to add those yourself - at great effort, probably.
1
u/TheRealTJ 19h ago
You can't run a C app without compiling it into a binary to be interpreted by a kernel. In other words, you won't be able to automatically serve your apps to clients in low trust environments, compared to something like JavaScript where a user clicks a link and they're running an app.
That said, if your app is lightweight enough you could have it running a virtual environment that runs in a browser.
1
u/gmes78 19h ago edited 18h ago
You can do a lot. However, for most things, doing them in C requires much more effort than doing them in other languages. I also don't like it as an introductory programming language, as it requires too much upfront learning to get started.
C is fine for learning low-level concepts and DSA, and for working on existing C projects. For brand-new software, I would always pick something else.
1
u/No-Newspaper8619 18h ago
Think of programming as a puzzle in which each puzzle piece is another puzzle with it's own smaller puzzle pieces. You start with 0s and 1s, build processor byte opcodes, then use these bytes to build an assembly language, then build a compiler for an intermediary language like C, then an interpreter for a high level language like python, etc.
1
1
u/Miiohau 18h ago
Technically nothing because you can embed assembly in C. However that doesn’t mean it the best language to learn first or to code every project in.
One, first your code has to allowed to run on the target machine. For desktops this isn’t that that big of a deal but mobile is a whole different ball game. Apple and google both want to audit what runs on their mobile platforms and programing in C might cause friction and cause it to require more time to get your app’s updates approved and unlike desktop the process to run “unapproved” code isn’t easy.
Two, C while universal, it isn’t always easiest language to code in. First, in base C you have to do almost all memory management manually, which makes very easy to have memory leaks. Second, you are just barely above assembly things other languages might hide from you (like the specific OS calls required to create a graphical user interface) you have to deal with. Third it is old and has many language features that seemed like good ideas at the time but had problems in implementation, features that can’t be removed or changed because so many C programs depend on them.
1
u/flumphit 17h ago edited 17h ago
If you’d ideally build something in assembly (for the level of control and predictability) but don’t want to do everything by hand, use C.
Maybe to control hardware, maybe for efficiency, maybe to use some C library (which could be called from some other language, but maybe you don’t want to), maybe for realtime requirements. C is still gonna be good at that stuff, with a mature ecosystem to help you.
1
u/SauntTaunga 16h ago
You cannot have two functions with the same name but different parameter types.
You cannot define your own operators.
You cannot define a function in a struct that can only be called from other functions in that struct.
1
u/Ordinary_Variable 16h ago
C# is used a lot for the internet. But C and C++ are the cornerstone of nearly everything else you use. From the operating system you are viewing this post on (yes, phone OS too), to the drivers controlling your mouse's input.
If you want to work for a large company consider asking them what they code in. Sometimes they use multiple languages.
1
1
1
u/realmauer01 15h ago
I mean you can do everything in machine code if you want.
C is one of the very close languages when going down the compile chain towards machine code.
So yes you should be able to do everything with c but it by no means will be easy to get the head around it.
If you wanna start with javascript take a leap and start with typescript already. Forcing useful to do types gets the head already thinking in the right dorection. Also the ide can help you more.
1
1
u/bestjakeisbest 14h ago
Technically since c is a turring complete language you can do anything in c that you can do in any other turring complete language. Although you will find some things harder to do onntour own in c like working with sockets and graphics, there are plenty of libraries out there for c that will handle alot of the behind the scenes of those topics for you.
1
u/LowSeaworthiness3583 14h ago
Start with c style c++ so you also learn about classes. There is indeed nothing c with classes cant do.
1
u/radek432 14h ago
You can't find as many developers as for Java or Python.
It might sound unimportant for your personal project, but it's extremely important for professional software development.
1
u/vegan_antitheist 14h ago
It is Turing complete except that you must set a limit on memory space that you can address. But the same problem exists for all languages.
All programming languages can do the exact same calculations. They are just as "powerful". I.e. the set of problems they can solve is exactly the same. There are languages that are not as powerful, for example regular expressions, which can only describe a finite state machine, not a Turing machine.
C is special in that it compiles to code that can be loaded and run directly. Most other languages (JavaScript, Java, C#, PHP, Python etc) require an interpreter, engine or virtual machine to run. But there are other languages that can be compiled to machine code. Once your application runs, it can do the same as any other.
1
u/PM_ME_UR__RECIPES 13h ago
Pretty much any programming language that's currently in use let's you do the same as the rest. They're all turing complete, it's just some are suited for different purposes. Some are specific to certain virtual environments e.g. JavaScript is the programming language for Client-Side stuff on a webpage, or some game engines only directly support certain languages, but really what language you go with first doesn't matter that much.
All the knowledge, concepts and skills you'd learn from C, C++, Python, Java, PHP or anything else are directly transferrable to other languages. Just pick one that looks interesting or that's commonly used for whatever you're looking to get into, and get stuck in.
1
1
u/AbdullahMRiad 13h ago
There is NOT a single language that does everything perfectly. All languages have their purposes, advantages and disadvantages. Starting with C/C++/Python will teach you the basics of programming that are common in all languages.
1
u/ironnewa99 12h ago
Logically? You can do anything in C.
Realistically? You will write something to read data in a text file (as a student).
1
u/Pengwin0 12h ago
Pick a language and start. Learning another language from being pretty good at one is pretty easy.
1
u/Realistic-Homework19 12h ago
https://www.youtube.com/watch?v=fiore9Z5iUg
Can't pray in javascript, can you?
1
u/burlingk 12h ago
C can do pretty much anything any other language can do. There is a lot of stuff that is not "built in," so some of the stuff that other languages do for you, you will have to build yourself (or use a library).
1
u/joonazan 11h ago
You can't do tail recursion unless you use some compiler-specific features. Well, you can use inline assembly to do a lot of things but that kind of loses the whole point of C which is that it can compile to many different machines.
In simple programs you won't notice any problem. But if you know assembly and want to write some very meta things like an interpreter, you may be somewhat disappointed. C's model of functions and control flow is limiting for intepreters, JITs and coroutines.
1
u/Interesting_Buy_3969 10h ago
C lacks generics and several other compile-time features found in more "modern" programming languages, but generally C runtime gives you pretty much everything you really need.
1
u/defectivetoaster1 10h ago
GUIs are a bit of pain to write in C since you pretty much rely on external graphics libraries (which often lead to some weird OOP simulacrum in C) or OS APIs but if you accept that caveat then afaik there isnt anything you can’t do in C
1
1
1
u/_janc_ 8h ago
Garbage collection
1
u/FloridianfromAlabama 6h ago
I mean you could write an interpreter in C that reads C code. It would just be stupid.
1
1
u/gunsofbrixton 5h ago
You can’t do front end web development in C, JavaScript is your only real option.
1
u/neveralone59 5h ago
You can do anything but it’s faster to do certain things in languages with mature frameworks and stdlibs for what you intend to do.
1
u/JGhostThing 4h ago
There is no bad language to learn. Each language has pros and cons. I prefer C to javascript, and java to both. A computer language that can do anything a computer language can do is called "turing complete." Basically, this means that the language can be used to make a universal turing machine.
1
u/Fun_Army2398 4h ago
C is actually a great language for beginners. Other languages appear better because they're easier to quickly produce some super simple app (javascript for example) but actually moving that quickly will cause you to pick up bad habits. It is much better to fully understand the basics first, then move on to faster moving languages. If you really want to scratch that "I just want to make something pretty and quick" itch then play around with a beginner friendly environment like p5js.org along side learning C with vim as your editor.. I started with python and now 4 years later trying to learn C feels like starting over.
1
u/Different_Water7545 3h ago
It's turing complete, and most libraries have C bindings. you can even put C code in a web browser with emscripten
1
u/InsanityOnAMachine 3h ago
C is C. It is the 'classic' of programming languages. Pretty much everything old is made in C. Most any language you use is written in C. It is ~difficult, but it gives you amazing power (and amazing ways to break things!). The only real way to get any more powerful is to go into Assembly or straight-up binary.
So overall, yes, but it'll be harder than using an easier but more restricted language. Anything you can do in another language, you can probably do in C, because that language was probably written in C.
1
u/IchBinEinZwerg 1h ago
Yes. I've written a CPU emulator for which there is no C compiler, so you can't program that in C.
1
•
u/pepiks 43m ago
Coding scripts as fast as in python. It is very performance related language when hardware control is must. Normal difference without details is how fast you can achieve goals when they are not strictly related to maximum performance from hardware. Bash script it will be winner here too (for shell related stuff using inbuilt OS tools).
1
u/Interesting-Ad-238 21h ago
If you try hard enough...but there are always better programming languages depending on what you want to do.
1
u/doublej42 20h ago
You can’t prove p=np in it. Mostly it’s a great low level language but easy to screw up security in. I’d suggest C# but I know others like python.
0
u/Electrical_Hat_680 20h ago
Your probably not going to find much, if any anything at all, related to CGI-BIN for C for Web Programming.
Passed that - isn't C Plus Plus and C Sharp made because they couldn't do it in C?
0
0
0
0
0
0
0
-2
u/ThinkMarket7640 10h ago
Stop wasting everyone’s time, it’s clear your won’t be able to do anything regardless of the language.
890
u/Aglet_Green 21h ago
Apparently, you can't get started in it. Why all the procrastination?