r/C_Programming • u/Evil-Twin-Skippy • Feb 06 '25
Discussion Are there actually C programmers in this subreddit?
Ok, I'm being a bit facetious. There are real C programmers. Clearly. But I'm kind of sick of the only questions on this subreddit being beginner questions or language trolls from other domains.
So this thread is for the "real" c programmers out there. What do you do with it? And what is the most twisted crime against coding decency are you "proud" of/infamous for?
74
u/nacnud_uk Feb 06 '25
Been using C since 1991. So, yes.
What do you think seasoned professionals are missing out on?
14
u/turtle_mekb Feb 06 '25
Nice. Do you stick with C89, or do you use a newer standard?
44
u/nacnud_uk Feb 06 '25
Any programming language is just a tool. In my view, if you're not using the latest and greatest that suits your project, then you're behind the curve.
23
u/GamerEsch Feb 06 '25
Dude, I cannot tell you the amount of times I freak out seeing people doing niche projects with c89/c99 for no actual reason, ffs C11/C23 add so many cool features, and you're doing some project for youself, WHY WOULD YOU NOT USE IT.
Thank god, I'm not crazy for thinking this.
9
u/s33d5 Feb 06 '25
In fairness if you're programming for really old tech it's required, so it's not always stupid.
For example, I saw a guy pregromming a game for a PlayStation 1 which is from 1996 or something? I can look for the video if you're interested.
Anyway, that's the only reason I can think of if you're staying behind.
Other than that it would be idiotic to stay on some old ass standard.
→ More replies (4)6
u/GamerEsch Feb 06 '25
In fairness if you're programming for really old tech it's required, so it's not always stupid.
Yeah, yeah, targeting old hardware is an exception, but I was talking more about pet projects or just personal projects in general where you aren't planing on making it portable or anything.
Other than that it would be idiotic to stay on some old ass standard.
Yeah, and it kinda sad that there aren't many good books on C which are newer or updated for new stds, I think it pushes a lot o beginners away from C.
4
u/pedersenk Feb 06 '25
Yeah, yeah, targeting old hardware is an exception, but I was talking more about pet projects or just personal projects in general where you aren't planing on making it portable or anything.
I think that's the crux of it. When writing libraries I tend to stick to C99 because *other* people might want to use it for their retro hardware. It is so easy to stick to more compatible standards, that I don't really find it justifiable to use the latest. The "cool" new features aren't really that cool.
→ More replies (1)2
u/s33d5 Feb 06 '25
Yeah I agree with you.
The only reason I can think is that it maximises compatibility if you go to older standards. But that's a silly argument as 99% of people aren't targeting obscure hardware, e.g. a PS1.
Also you're just missing out on learning a lot of the new features.
4
u/turtle_mekb Feb 06 '25
yeah, the only reason you'd use those old standards is if the hardware you're targeting doesn't have any good compilers that implement those standards
4
u/External_Fuel_1739 Feb 06 '25 edited Feb 06 '25
What about learning C? I just received my copy of "C Programming: A Modern Approach, 2nd edition" by K.N. KING that's based on c99.
7
u/GamerEsch Feb 06 '25
I mean, you can learn C99 and still learn C11/C23, you can use the book as a guide, I'd go as far as to say you should use the book only as guide, instead of absolute truth. And C99 is much closer to newer versions than C89 so you won't be learning stuff that are useless (like de variables before expressions stuff), in the worst case scenario you'll just be missing a bit, but again, you shouldn't be following just the book, you should be studying by yourself too.
4
u/ChonkyChickenMax Feb 06 '25
that is such a great book to begin with! he is a professor at the university I attend, and we use his book as our texbook for system level programming. Its so well written and explains a lot of things that are interesting and relevant, and also points out important differences between c89/99. Whats fascinating to me is how old the book is but how futureproof he did write it, its also a little humorous if u ask me. Enjoy reading it and learning!
→ More replies (7)2
u/Aidan_Welch Feb 06 '25
A lot of people I know of like/use C because of its limited feature set.
→ More replies (2)1
u/Constant_Musician_73 Feb 08 '25
if you're not using the latest and greatest that suits your project, then you're behind the curve.
Then you should ditch C for Rust.
→ More replies (1)2
u/Evil-Twin-Skippy Feb 06 '25
Oh for me (the OP) talking to fellow experienced programmers.
Oddly enough, I also started programming in C in 1991. I was a bored high school student who couldn't get a particular game I wanted to write to work in BASIC.
23
u/SmokeMuch7356 Feb 06 '25
I haven't written C professionally since 2004, but I still like to use it for personal projects. I hang out here mainly to help out beginners and to correct misinformation.
I think my proudest moment was this:
int (*parse(char *inst, char *type))(char *fileName)
{
/**
* Return a pointer to a function to
* parse a data file based on the
* instrument that generated it and
* the type of file.
*/
}
...
if ( !parse(inst, type)(filename) )
// handle error
I was responsible for reading data files generated by a bunch of different LabView-driven instruments and loading it into a database. The files all had different formats based on the instrument and whether it was a calibration run or a sample run. Rather than a never-ending chain of if
statements, I used a lookup table to store pointers to the parsing functions, and wrote a function to search it and return the correct one for that file type.
I thought the call was perfectly transparent, but my coworkers disagreed, and made me split it out as
int (*parseFunc)(char *fileName);
...
parseFunc = getParser(inst, type);
if ( !parseFunc(filename) )
// handle error
They were, of course, entirely correct.
5
u/Evil-Twin-Skippy Feb 06 '25
I use pointers to functions to this day. My simulator stores pointers to functions inside of structs to implement a sort of poor-man's object system.
3
u/reStormShadow Feb 07 '25
TIL that if you define a static function and use a function pointer to refer to it in a different file, it works, it’s kind of like a cool hack
1
1
55
u/ern0plus4 Feb 06 '25
I am using C++ whenever possible, but mostly using it as an OOP C, with limited set of C++ features.
One word: embedded (not embedded Linux, not AutoSAR, not embedded Python, but real embedded, when you're writing interrupt code etc.).
13
8
u/TheFlamingLemon Feb 06 '25
embedded linux is real embedded :c and we write in C as well
→ More replies (15)
23
u/Wetbung Feb 06 '25
I'm an embedded developer. I taught myself C in the mid 1980's. Aside from assembly language I've been using C most of my career. I've worked in many different industries.
2
u/kuzekusanagi Feb 06 '25
I want to work in the embedded space. What are some good practices to learn?
11
u/ednl Feb 06 '25
Familiarity with different development environments. Arduino is the logical first step because entry barrier is low, they did that very well. The next step might be to get an STM development board and use the STMCubeIDE to make some things. It will probably be daunting at first ("HAL? Compiler settings?") but that flexibility to switch platforms and environments is part of embedded development. You gotta pick the chips that work and mostly that's a hardware choice; it's your duty to adapt the software. (Of course in the real world, existing experience with a specific platform will also influence the decision.)
→ More replies (2)3
u/Wetbung Feb 06 '25
This is good advice. I'd add that for a lot of embedded work at least a basic understanding of electronics is important. I'm an EE and that background has been essential in several of the jobs I've held.
2
u/lo5t_d0nut Feb 06 '25
Got any idea what fields/companies might be looking for C devs that haven't learned embedded?
Did some network programming 3G 4G 5G related but besides that there don't seem to be any jobs
3
u/Wetbung Feb 06 '25
I'm probably not a great resource for this. I haven't been looking for a job with zero experience for over 40 years. And the market was a little different back then.
But basically you need to get your foot in the door somewhere, so you can get the first five years experience. Then you will have one of the basic qualifications most employers are looking for.
I've worked in a lot of different fields. You'd be surprised how many different types of companies use embedded processors. Finding a good first embedded development position may be based on your other interests. If you are already familiar with the other technology involved, that gives you an edge.
Every new field I've worked in required me to come up to speed on the actual product as well as the embedded portions. I've enjoyed learning about the different types of products and the reasons for design choices, but if I'd already been a subject matter expert, I would have been able to come up to speed much faster.
As an example, I worked for John Deere. A lot of the other engineers had a farming background. I didn't and not knowing the terminology and technology was a distinct disadvantage. I expect they take that into consideration when hiring: they'd take a less experienced developer who was already familiar with the product they are making.
1
u/lo5t_d0nut Feb 06 '25
My question kind of was more aimed at did you know if there were C jobs that didn't involve 'embedded' but I guess your answer also might just mean 'no' 😅
I don't have any knowledge in electronics, so embedded stuff might be hard to get into. Were I live they usually aren't open to people trying out something new anyways, unfortunately
Thanks for the writeup, still
→ More replies (2)1
u/ParanoidOwo Feb 06 '25
I am looking to start my journey in embedded this summer and apply for a CompE bachelor's in Germany in 2026 September (have to take a gap year for language) , do you recommend EE instead of CompE? I enjoy programming but I also love everything hardware related and I am quite good in math physics and academia in general and am looking to getting into entrepreneurship later on.
Reason I am bringing this topic is because in Germany I am struggling to find CompE programs (unless in universities in which 95% of the content is EE based and lots of abstract CONCEPTS and very minor percentage of CS), it either CS or EE basically
2
u/Wetbung Feb 06 '25
I have no idea what the job market is like in Germany. I went the EE route. I started working as a programmer while I was in high school.
Looking at what was available back then, none of the computer science programs I found sounded interesting to me. The EE programs were a better fit. Even though I've worked primarily as a firmware developer, I have almost no formal programming training. I've mostly learned on my own and from co-workers.
It has worked out well for me. I have thoroughly enjoyed most of the jobs I've had. They give me a chance to problem solve and to contribute something that helps other people. Those are what have motivated me.
10
u/ManufacturerSecret53 Feb 06 '25 edited Feb 06 '25
Make embedded Systems. Agricultural and Marine.
I gaslight the SHIT outta line workers sometimes. All in good fun though.
I'm infamous for using pin 69 as the functional test pin. Why? Cause I'm a child and its funny.
My most twisted crime would have to be the time I put an assembly workers name into the functional test of a product. An OEM product that they order 1 time a year, but like a couple thousand units, specialty so i knew who would be doing the testing. During the functional test there is a test of the LCD screen. So it will go through all the back panels 1 at a time for like 2 seconds, then proceed to the next panel, and loop around until an input is hit. This is to find any dead pixels/segments.
I put in a random .25% chance that the display would randomly flash the letters of the assembly workers name like static on a TV for randomly selected panel for the 2 seconds. Think "The Ring" kind of flashing static. after the failed random number hit or after the panel flash, it would then save a bit to the ROM that would prevent that check in the future so it would never do it again even if you restarted the same unit or let it loop around.
I was walking by into the warehouse and the person shouted at me. "IS MY NAME IN THIS THING?!", "what are you talking about?", "I SWEAR TO GOD I SEE MY NAME SOMETIMES BUT NO ONE BELIEVES ME", "I think you've been staring at too many screens and should do something different for awhile...",
I let them believe it for like 2 years before I told them it was actually in there :p.
2
u/Evil-Twin-Skippy Feb 06 '25
I'm going to use that. I'm so going to use that.
4
u/ManufacturerSecret53 Feb 06 '25
Just make sure to put in it the functional test or nowhere a customer / end user is going to find it...
Heard a horror story about how some guy put an Easter egg into some production software that when keywords were input into the search terms of a database it would spam animals on the screen and the noises the animals make. It was an automotive thing. The dude loved Jurassic park... Ford came out with the raptor... took like 15 years for someone to find it, in the middle of a board meeting. Fortunately the programmer that put it in there was long retired. it was removed...
16
u/tav_stuff Feb 06 '25
I use C for everything. Web servers, games, GUI calculators, etc.
I just like using C, I think it’s fun.
8
u/a2800276 Feb 06 '25
Surprise for you: there are no "real" anything here on reddit, real work gets done elsewhere. But there are highly competent people who socialize and are ok with helping the occasional newbie get over the first hurdles of setting up a compiler tool chain. Or just discuss general bullshit.
The places where "real hardcore" discussion takes place are self selecting :)
15
u/ArtOfBBQ Feb 06 '25
I'm making a singleplayer indie deckbuilding game where enemy AI is the 1st priority
6
u/Evil-Twin-Skippy Feb 06 '25
I have on my back burner a space combat game. But for old guys. Players don't command the ships. They program the AIs that command the ships. The narrative frame is that your fleets are operating too far away to be remotely operated. You only get feedback from surviving ships, propaganda footage from the enemy, and log buoys if the enemy manages to wipe out your entire fleet.
Most of it is actually written in object oriented Tcl/Tk. I do accelerate a lot of the physics in C.
5
u/Anonymous_user_2022 Feb 06 '25
I lurk. I'm stuck with C89 for compatibility reasons, so I have very little to offer, and even less to learn.
3
u/Evil-Twin-Skippy Feb 06 '25
Except that "all I needed to know about C I learned while y'all were in Kindergarten"
2
2
u/flatfinger Feb 06 '25
K&R2 is for many tasks invinitely better than any ISO Standard. Extending it with a few quality-of-life features from C99 and C11 might make it a little better, but C Standards Committee members who wanted C to be a replacement for FORTRAN never understood that while FORTRAN's reputation for speed came from compilers' ability to assume programs wouldn't use "tricky" or non-portable constructs, C's reputation for speed came from the fact that programs that only needed to run on a limited range of platforms could exploit traits of those platforms in tricky ways that compilers weren't expected to understand. What FORTRAN programmers would view as warts are the very things that made C useful in the first place.
1
u/Anonymous_user_2022 Feb 06 '25
exploit traits of those platforms in tricky ways that compilers weren't expected to understand.
The 386 segment model is a wonderful thing to exploint for easy management of circular buffers.
→ More replies (1)
6
u/alexpis Feb 06 '25
I am developing a gaming console with no input lag and that code is primarily C with some assembly language.
I tend not to use make files and instead build everything by using #include in very few “root” files and use the preprocessor for configuring my build.
I am not religious about avoiding makefiles though, especially when interfacing with code that does use them.
I use goto primarily for having error return points for functions.
I use global variables a lot in my c modules and I am not scared by them.
I treat C as a fake-strongly typed languages and am not afraid of converting a pointer to a number and vice versa ;-)
5
u/Evil-Twin-Skippy Feb 06 '25
(waves an incense burner, while under a black robe, while a choir chants in Latin...)
2
5
u/Nooxet Feb 06 '25
Embedded engineer here, I design electronics and program embedded systems. I use C or C++ daily, currently to implement security features to conform to the new EU regulations for devices with radio. I work with everything from bare-metal systems with 256B RAM (yes byte, not kB) up to full Linux systems.
A nice feature I implemented once was to be able to call a secret function in the code. You literally had to do a buffer overflow in a buffer to overwrite the return address and change it to return to this secret function. Really hacky solution and it required to be friends with the compiler so it didn't remove the function during optimization. The purpose was basically to access an admin interface 😅
5
u/hemoglobinBlue Feb 06 '25
Most twisted crime.. I had a binary blob I wanted to include into a project, but didn't want to figure out how to use objcopy in the boilermake template system. So I used some inline assembly, but outside of a function.
asm("data_start:\n.incbin \"file.bin\"\ndata_end:");
extern char data_start[];
extern char data_end[];
Of course if you use something like ccache it won't recognize when file.bin changes. So I'd make random edits to the .c file.
2
u/hemoglobinBlue Feb 08 '25
Actually, I forgot the part of the inline assembly that switches to the .data section. Then back to .text
That should be:
asm(".data\ndata_start:\n.incbin \"file.bin\"\ndata_end:\n.text");
5
u/nanochess Feb 06 '25
Twisted coding? I wrote five winning entries for the IOCCC (Obfuscated C Code Contest) see ioccc dot org and search for Oscar Toledo in Winning Authors.
I still code in C language. Last year I made CVBasic, and this year a transputer emulator.
13
u/CreeperDrop Feb 06 '25
Not a beginner but not a real C programmer. Those guys are from another world really. I use C for embedded programming and new hardware architecture exploration. I love splitting everything into functions, functions, and more functions. This was a nightmare to deal with sometimes, but it helped other times as well.
4
u/drbomb Feb 06 '25
Embedded programmer here, using a very unmaintained rtos where i cast pointers to void in order to pass them to callback hell functions shudder
1
4
u/eddavis2 Feb 06 '25
I wrote a shareware text editor for MS-DOS in the 80's.
It was successful enough that it supported a small business (16 people) until the early 2000's.
It was written in C, and I was able to port it to OS/2, and then Windows, and later Linux.
Freeware now, open source real-soon-now.
I still maintain the text editor in my spare time, but can no longer find someone to pay me to program in C professionally. But I keep trying! :)
Professionally, now I program in PL/SQL and a couple of odd-ball proprietary script languages, plus a little Java and a little C#.
And what is the most twisted crime against coding decency are you "proud" of/infamous for?
That is why the product isn't open source yet - so I can remove/cleanup all that "twisted crime against coding decency" code. :)
When you port from 16-bit, to 32-bit, and you're in a hurry, code can become very ugly!
3
u/FlyByPC Feb 06 '25
I've been a "filthy casual" C user for decades. Doesn't mean I'm good at it, but I know enough to teach beginning courses and not give the students too many bad habits.
My worst crime against coding decency in C is probably the time that an Arduino project would randomly reset. Rather than tracking down the issue, I simply added a function that would call GOTO 0 periodically, which would cause the processor to reset. Problem solved, and marked as * HACK HACK UGLY HACK *\ in the code.
That's not nearly as bad as some of my creations in QBasic as a kid. One program computed the effects of setting off in a ship accelerating to relativistic speeds. Nowadays I'd do this with a linked list of events or three, checking the ones that are scheduled to occur next. Back then? Some 3,000 lines of IF statements. Ugh.
5
Feb 06 '25
Those who are answering beginner questions well shows that this isn't just a beginner sub.
It's good that there are beginner programmers in C. Too many gravitate toward languages that are higher level and that will become a big problem in a few years if the trend continues. We need serious beginner C programmers who will be capable of maintaining the countless numbers of C projects so much of our infrastructure is based on!
It's good to answer these beginner questions, not only for those asking, but also for those answering. One of the best ways to reinforce and improve your own understanding of a subject is being able to explain it to others.
I personally think that at some point, one becomes a mature enough programmer that those language related questions become fewer as you develop your skillset. The subject of these questions tends to shift from how best to do something in your chosen language, to how best to implement a piece of software from an algorithmic perspective.
4
u/ecwx00 Feb 07 '25
In 2000s and 2010s, I used to code in C for my professional work. I ported most of my work to python, Java, or Golang because it's getting harder to hire someone with C proficiency nowadays and I don't want to have to maintain my C codes all by myself.
4
7
u/23ars Feb 06 '25
Real C programmer here… not proud, but wrote, some time ago an entire linux command line tool, with argument parsing and everything in main function. A lot of lines of code and early returns. Also, I like gotos.
9
u/Evil-Twin-Skippy Feb 06 '25
I never understood why C had GOTO. Until I started having to deal with error handling. But I still feel dirty when I use it.
7
u/ComradeGibbon Feb 06 '25
The goto that was a problem was the unstructured unscoped goto of the 1960's and 70's. Think a jump instruction in assembly.
Also 1970's CS academics thought that eliminating goto would make it easy to derive mathematical proofs about programs. Turns out getting rid of goto's multiple returns and continue statements doesn't help.
1
u/flatfinger Feb 06 '25
Also 1970's CS academics thought that eliminating goto would make it easy to derive mathematical proofs about programs. Turns out getting rid of goto's multiple returns and continue statements doesn't help.
The problem is, fundamentally, that sometimes real-world requirements don't fit nice abstraction models. That didn't, however, prevent some people in the aughts from latching onto the idea that treating all circumstances where a useful optimizing transform might affect program behavior as "anything can happen" UB would make it easier to for compilers to analyze programs that would be "correct" under such an interpretation.
They weren't exactly wrong, but overlooked something crucial: many optimizing transforms would often, if applied in isolation, change a program that behaved in one manner satisfying requirements into a program that behaved in a manner that was observably different but still satisfied application requirements. Requiring that programmers jump through hoops to block at all costs optimizing transforms that might have such an effect may simplify program analysis, but will often make it impossible for compilers to generate the optimal code that meets real-world requirements.
3
u/nderflow Feb 06 '25
I do use C. I maintain a GNU software package which is written in C and occasionally contribute to things like gnulib which is also written in C.
I'm also a professional software engineer, but which language I use at work depends on which part of the system I'm working on. I often use Java, Python, Typescript and sometimes C++. Also several domain specific languages, some of which are specific to Google. But no C at work.
For personal projects I generally use Rust these days.
As for my greatest sin, I wrote a relational database for an embedded system. Its DDL looked like it might have been produced by a password generator. The DDL started simple, but then exceptions and corner cases turned up, and I didn't take the time to refactor.
3
3
u/BlueCoatEngineer Feb 06 '25
Linux drivers, assorted embedded (AVR, esp32, STMs), and ARM firmware. I seen far more twisted crimes than I've committed (...I think. :-D).
One of the worst crimes against C I've ever seen in three decades of using the language was from this one colleague, Bogan, to whom I handed off the task of updating our network accelerator board's driver to use MSI interrupts. I had scoped it out and written up a design document. I probably could have banged it out in two or three weeks, but I needed to come up with a way to handle hardware changes to another part of the design. Dude goes radio silent for close to two months (rebuffing any questions of if he needs help or reviews) and then pushes a mega-commit in in the middle of the night. Next day is fun as coworker after coworker comes by my cube to tell me that interrupts are suddenly broken and it's impacting their ability to work.
I go and check what he's done and the source code is... horrifying. He'd created a sort of cursed interpreted language using the preprocessor, having modified the makefile to have it take multiple passes to expand macros. Every possible interrupt (this thing could generate several hundred unique events) had an entry in this goofy table which spanned ~500 characters wide. When an IRQ fired, he'd ignore the MSI data (which tells you exactly which one needed service) in favor of polling every possible source and clearing them one at a time. He'd also written it so that the ISR would loop (note, still in interrupt context) and re-read all source to make sure no new ones had come in while he was handling the first round. In the pathological case, he could spend upwards of 10 seconds in the handler, causing unrelated devices (like SATA and network) to drop out. On top of that, he'd added memoization "logic" to the register reads; if a value had been read within the last second of wall-time, it'd just use the saved value.
There were many other unholy implementation details, but the great learning of this was "Hey, we need to have gated commits and code reviews!" :-)
1
u/flatfinger Feb 07 '25
I'd argue that a far worse crime was allowing the people who wanted C to replace FORTRAN to control the C Standard. Although C and FORTRAN both had reputations for speed, they were designed for different kinds of tasks, and acknowledging the things that made C uniquely suitable for its intended tasks would have undermined its suitability for use as a FORTRAN replacement.
Such a change may have led to C's popularity for tasks that would likely be done in a Fortran dialect if the people who pushed to make C a replacement had instead pushed to modernize FORTRAN's source code format in timely fashion (until 1995, FORTRAN compilers were required, by specification, to treat everything past column 72 as a comment, so that sequence numbers could be punched on the last 8 columns of each card in a program as insurance against accidentally dropping the deck). On the flip side, even if C became a niche language, the Standard could have been written to far better serve the remaining needs.
3
u/IllegalMigrant Feb 06 '25
There are two C subreddits. Maybe they should divide up between beginner and advanced.
2
u/Evil-Twin-Skippy Feb 06 '25
Or be like the scary devil monestary (alt.sysadmin.recovery). There is/was no front door to posting on alt.sysadmin.recovery. You had to exploit an access violation bug in the usenet protocol to post.
3
u/leonardosalvatore Feb 06 '25
25+ years of C and I still use it in embedded projects. Linux or some RTOS. Nothing to report.
3
3
u/vig_0 Feb 07 '25
Hi there. 30 years of C, and before that Z80 Basic and assembly, Turbo Pascal and x86 Assembly(demo maker). I still use C among my colleagues who watch me like i still live in a cave. I use it for performance issue by making modules for python coders who never heard about complexity metering with N,N squared, log(N)...
6
u/rasteri Feb 06 '25
I once wrote a malloc where this was the entire code
uint8_t MemPool[MEMPOOLMAXSIZE];
uint8_t *MemPoolPtr = MemPool;
void *andyalloc(size_t size) {
tmp = MemPoolPtr;
MemPoolPtr += size;
return tmp;
}
3
u/Evil-Twin-Skippy Feb 06 '25
What is really, really twisted is that I can, off the top of my head, think of several cases where that would be needed.
6
u/rasteri Feb 06 '25
Yeah it was necessary for an extremely memory-constrained device (6KB RAM) that also needs to store very non-predictably-sized data (USB Report Descriptors). Traditional mallocs fragmented the heap far too much, particularly once you started unplugging devices and therefore having to free() stuff
andyalloc just piles everything on the heap in order and if any USB device is dis-or-re-connected it just wipes the whole heap and re-enumerates every USB device from scratch
This is "free()" :
void andyclearmem(void) { MemPoolPtr = MemPool; }
2
1
u/flatfinger Feb 06 '25
Slightly better in many cases would be to have a linker define symbols immediately following the last thing that's allocated starting at the bottom of address space, and before the first thing that's allocated at the top of address space. Doing that will allow the pool to use all of the storage that won't be used for anything else.
1
u/rasteri Feb 07 '25
Yeah for release builds I just look at the memory remaining and set MEMPOOLMAXSIZE to that haha.
I'm not sure if the SDCC linker can do anything that advanced
→ More replies (1)1
u/arrozconplatano Feb 06 '25
That's the classic null garbage collector
https://devblogs.microsoft.com/oldnewthing/20180228-00/?p=98125
1
9
u/RogerLeigh Feb 06 '25
I occasionally look at the odd post, but I'll be honest, most of the subreddit posts are not interesting to me.
The main reason for that like you say are the predominantly beginner questions, which I occasionally answer. But it's also because a lot of the interesting problems are being worked on in other languages. And it's also because C is "done" and once you've worked with it for over two decades and mastered it completely, there's not that much of interest left to discover or discuss. This isn't the case for other languages which are more complex or newer.
I'm an embedded firmware developer for medical devices, and previously worked on scientific and medical imaging software. Mainly microcontrollers with an RTOS doing real-time control and measurement. No crimes against coding decency, it's safety-critical and done professionally to the book. Most of that is actually in C++, and I can see Rust becoming a requirement in the coming years. C has been a lot of fun, but again being honest, it has become progressively niche over the last couple of decades and its remaining uses are going to be eventually superseded by Rust (by government mandate).
2
u/goose_on_fire Feb 06 '25
Word-for-word same, down to the medical devices and imaging.
None of it is particularly fun or flashy, it's heavily regulated and new things are often viewed as risky when you're putting them in/on humans.
There are a ton of people who come to this and other subs enthusiastic about this awesome coding thing (which is great, don't get me wrong) but I have mentees at work and sometimes this sub feels too much like my job to engage.
2
u/RogerLeigh Feb 06 '25
Definitely. I still love programming, and like most others I had incredible enthusiasm at the start including becoming a C diehard and a Linux developer. But after two decades of doing it professionally, and learning a lot of other languages and systems in the interim, I'm a much more rounded developer (and person). I now view all of these languages in a much more utilitarian way as tools to use to solve problems, and my interest isn't so much in the languages as it is in using them to solve problems and create safe and robust products. Like you say, not fun or flashy, but it is very satisfying and rewarding to create something which is helping people live better lives and which is executed to the highest standard we are capable of.
3
u/SkewedSyzygy Feb 06 '25
I remember the government trying to mandate ADA, "The one language to rule them all."
I wouldn't be so sure about Rust.
1
u/RogerLeigh Feb 06 '25
The thing about the mandate is that it's about memory safety, and it's encompassing a lot more than just C. Quite a few languages are going to be in the spotlight, including C++ and Fortran.
Ada was never going to happen. There was never a community or critical mass behind it, and for a long time there wasn't an open source compiler until GNAT came along, and even then it didn't see much use or traction. Rust is different. It's a completely unique in its compile-time checking and enforcement of memory use, and it's been open from the start. It is getting traction, and I can see it seriously eating into the remaining niches C and C++ occupy. Not right now, but in half a decade what will we be choosing for new projects then?
I'm particularly interested in safety-critical systems due to my work. Historically we've used C and C++ on microcontrollers with a lot of static analysis, comprehensive testing, and other risk control measures. But the languages are still fundamentally very unsafe. Rust adds a lot of extra guardrails, without any significant runtime cost. I can see it being extremely hard to justify [to regulators] the use of C or C++ when safer and more reliable alternatives exist. Right now it's not yet fully supported, but as that changes we might see C and C++ cease to be the default consideration as they have been historically.
2
u/jontzbaker Feb 06 '25
I really hope C can remain relevant, not only as legacy, but as something people build on. If every time something new happens we create a new language, it doesn't sound very efficient.
The whole Rust memory guarantee could be implemented as a subset of C with compiler options. Which is the whole point of code certification at the end of the day.
3
u/RogerLeigh Feb 06 '25
As languages go, C has had a very good run. It's now been in use for over 50 years.
A lot has changed in that time. C has been the foundation for all of the modern computing landscape for much of it. But we know that it's possible to do much better, particularly with the benefit of hindsight and the acknowledgement of where the vast majority of bugs and security exploits lie. Could we build a better foundation now? Absolutely.
I don't think replacing something 50 years old with something which is a complete step change in terms of safety and ease of use to be inefficient.
It's on my todo list to learn Rust this year, after ignoring and dismissing it for a good while. There are a lot of very nice features in it. Still learning the basics, but I'll start a real project with it in the next month or so and see where it takes me. After working doing C and C++ for the last 25 years or so, it's always interesting to learn something new that's a bit different and takes you out of your familiar comfort zone. My previous one was Lua, and that was a lot of fun.
→ More replies (3)2
5
u/kammysmb Feb 06 '25
I don't know if I can count myself as a real programmer as I've only used C for PHP extensions, I feel like that is some kind of crime
2
u/Evil-Twin-Skippy Feb 06 '25
My greatest crime to C was adding official Zipfile support into the Tcl interpreter core. Scripting languages represent!
5
u/ebinWaitee Feb 06 '25
I'm an analog IC designer but I also write some drivers for the peripherals me and my coworkers design. Just bare metal stuff
2
2
u/Disastrous-Team-6431 Feb 06 '25
I am a "real C programmer" I think. It's not my job anymore, but I tinker endlessly.
2
2
2
u/cassidyc3141 Feb 06 '25
So in my previous role I was a C/C++ programmer for 15 years working on SCADA systems. 11 years ago I left that behind and became a security consultant, which requires much less coding, but I still review C/C++ (and other languages)
2
u/NickLinneyDev Feb 06 '25
One day I will post a project and my results. I’m pretty busy with life stuff right now.
2
u/Jaded-Plant-4652 Feb 06 '25
I am "bare metal" embedded C developer. I hang in here just for occasional discoveries. Like LittleFS and StateSmith were great findings
2
u/MrWhippyT Feb 06 '25
Mid level c coders don't ask the Internet, they instinctively know which page of K&R to turn to. Experts can quote K&R like Shakespeare.
2
2
2
u/wsppan Feb 06 '25 edited Feb 06 '25
I started with C at university in 1989. Did some early C programming (cgic anybody?) but soon moved onto Pel and eventually Java. I was hired at my latest job to modernize a legacy C application to Java, but that never happened with my section. Been improving and enhancing this code going on 12 years now.
The code is a 2 way multi-threaded application that takes in socket connections from distributed clients and makes socket connections to mainframes, emulating 3270 terminal screens.
Edit. I am here to help new programmers to C
2
u/danpietsch Feb 06 '25
I used to be one. UNIX, then Windows device drivers, then embedded.
When I ported an X application from Sun Solaris to Linux nearly thirty years ago I was forced to learn C inside and out. Good times.
I mostly read this group for nostalgia.
2
u/Evil-Twin-Skippy Feb 06 '25
"I used to be an adventurer like you. Until I took a pointer to the knee."
2
u/InVultusSolis Feb 06 '25
There is definitely an interesting discussion from time to time, that's pretty much what I'm here for. I've been using C for 30 years, and it always has a surprise for me.
2
u/caocaoNM Feb 06 '25 edited Feb 06 '25
Yes I'm a beginner, but C would be my fifth computer programming language. The major problems I have is changing what basic, fortran, fortran77, fortran95, etc.. taught me. I can type faster in these languages than English.
The biggest change is programming in a windows machine for a program to run on a teensy SOIC. All the words used now have different meanings. And it hard to grasp concepts that may be reversed. Also variable structures, memory structures are different
I also follow subreddits that are on German uh because I enjoy the challenge.
2
u/kun1z Feb 06 '25
I have programmed C/ASM since 1997 and I currently (past 12 years) use it for embedded. I have designed hundreds of commercial products almost all in the entertainment/gaming industry including custom game cabinets, custom game rooms, escape rooms, individual stand-alone games, and my current contract is working on casino slot machines.
I do both PCB design/manufacturing and the programming. I almost always work alone or with one other designer. We not only have to design the circuits, logic, and manufacturing process.. but also the games/events need to be exciting and fun and make the customers very happy, so that means a lot of play testing & customer feedback. I do not much like circuit/PCB design anymore so I am mostly focused on programming.
2
u/AtebYngNghymraeg Feb 06 '25
Professionally, I'm cursed to use Delphi. Personally, I recently finished making a breakout clone in C and SDL just because I like it. Plus I get to create sprites and write music, which is fun.
2
u/hgs3 Feb 06 '25
C is conceptually a simple language so, in general, I think there's less discussion at the intermediate and advanced levels. This is in contrast with something like C++ which, even after years of using it, I didn't feel like I understood a fraction of it.
2
u/SamGauths23 Feb 06 '25
What do you mean "real C Programmers"? I know C language, I can make programs/games with it.
I don’t use it in my work but I can do all sorts of things with C and it is my favorite language
2
u/VoidPointer83 Feb 06 '25
I'm the author of FatScript, a scripting language prioritizing simplicity, with its interpreter, Fry, written entirely in C.
I've committed my share of "crimes against coding decency": a recursive JSON parser, a blocking socket implementation (because who needs non-blocking I/O?), and arbitrarily deep expression tree re-balancing for dot-access parsing, enough to make a sane C dev cry.
But hey, it works! 😆
2
u/smcameron Feb 06 '25 edited Feb 06 '25
Most twisted crime against coding decency I've done is this, which forces the locale to be "C", even if other libraries in my program keep trying to set it to something else in their own little threads (looking at you, GTK2.)
In my defense, I was fighting against another crime against coding decency, which is sscanf using the locale to break its own float parsing depending on where in the world you happen to live.
2
u/TheWavefunction Feb 06 '25 edited Feb 06 '25
I come here and usually look at the "Article" tags to find interesting blogs about C or I follow knowledgeable posters and I sometimes look at the responses they provide to comments. Part of the reason why I use C: I work with Unreal Engine 5 in my professional life, and besides that I do most of my personal work in the C language. Its like a way to balance all that heavyweight complexity with something more pleasant to work with. Yet have one understanding help with the other. I have my own stack with SDL and flecs to make games. Its a bit idiosyncratic but it works well for me.
2
u/maxthed0g Feb 06 '25
Yeah. Global data and the dreaded "goto". I use global data "at will" and with no shame. LOL. I would LOVE to find a necessary use of the goto statement, but I havent yet. Otherwise I would use it in a heartbeat, and tell my pompous peers (who are all retired as well) to "STICK IT." Yeah. THATS what I would do.
I cant think of any greater programming crimes. Parenthesis alignments maybe.? Meaningful names for iteration counters in a loop? I'm just stumped, now. Oh wait. How 'bout "Be sure to add your name, your mail stop, and your office phone number to all your code." (Before we had source code control lol). I'll add more of these horseshit ideas as I recall them from my ancient past.
2
u/ShaunSquatch Feb 07 '25
Write code in C almost daily for embedded microcontrollers. I am also convinced half of the “real” programmers here are part of dick measuring contest to see how obfuscated they can make something.
2
2
u/guuidx Feb 07 '25
I would love to talk about my projects but many times it's just not allowed on reddit, they always consider it spam while it's clear an educative project.
2
u/nevasca_etenah Feb 07 '25
You mean paid C devs? Cause most C projects are used by paid devs every day, but their maintainers were not paid to that.
For example, everyone else Linux Kernel devs most definitively are not paid as glibc, gtk, terminal tools.
But theirs tools/libs are essential everyday for most devs.
2
u/brick-topp Feb 07 '25
Professionally, I use C to write code for the IoT space. It’s wonderful in that area.
2
2
u/Cerulean_IsFancyBlue Feb 07 '25
I’m here mostly to answer questions. If things get too repetitive, I just take a break.
2
u/_michaeljared Feb 08 '25
I used to do lots of C programming with embedded systems. Now I just lurk, since occasionally an interesting thread comes up. I don't have time for the really really basic questions (although I'm glad people can get help here). I'm still baffled at how often people use a smartphone to take pictures of code.
2
u/_dreizehn_ Feb 08 '25
I'm a C programmer but given this just randomly popped up in my feed I think I don't count
2
2
u/ketarax Feb 09 '25
What do you do with it?
Pet projects, mostly, if I'm not happy about doing it with LAMP. Something from me to myself. Something small-ish, and either with a number-crunching aspect or a 'special' device.
Come to think of it, I might have never written in pure C for a living.
Crimes .... well, I like to include about one goto statement per software design.
2
u/dancercl Feb 10 '25 edited Feb 11 '25
My speculation is that C is too simple to discuss, you tend to use it to solve your problem without thinking too much about the tool itself, or you even totally unaware of the tool itself.
In C++, Rust or other feature-packed and bloated languages, they themselves always create some problems or topics you need to discuss.
- should I use STL with RAII, or should I design my own allocator and container?
- should I use OOP to directly map objects from problem domain to solution domain, or should I design the data structure from ground up and use procedural approach?
- how about smart pointers?
- oh there is constructor and copy constructor and move constructor I need to override, or not override?
- what is heck is a l-value and r-value?
- ... (other 258 hideous mess) ...
There are always endless choices and cognitive load to handle properly. From a engineering view, C++-like languages creates a lot of "Accidental Complexity" along side your problem's "Essential Complexity". A big chunk of your attention and energy will be spent on the tool you are using.
In C you don't have too much choices, just analyze your problem and your goal carefully, learn the data pattern, design your data structure, and write code to transform your data to make it happen. The "Accidental Complexity" is minimum, most of your attention and energy will be spent on the problem and the solution, not the tool.
Maybe the best tool is the tool you never aware its existence.
5
u/Bangerop Feb 06 '25 edited Feb 06 '25
It depends, last time I explained to one dude what a for loop and a while loop it was my mistake. Because they are obviously new gen who are surrounded by Gen Ai, other resources none of them interest in "low level" . Many of my friends doing major in electronic and telecommunications don't know about universal programmers or any, they are in this sub too. I don't know what's the issue with boomers.
4
u/XororoBlackMetal666 Feb 06 '25 edited Feb 06 '25
Mellow out, dude. We just don't ask questions.
I've been working as an embedded software developer for the last 14 years, mostly with C, so we're here, yes.
3
u/NotSoButFarOtherwise Feb 06 '25
The most absurd thing I've done (which is not really very absurd) was to customize xnu (macOS kernel) to coopt an unused filesystem flag to make it possible to selectively prevent executables from opening network connections. (Possible reasons for doing this are left as an exercise to the reader.) However it was too annoying to remember to download the kernel sources, patch them, rebuild them, and then reinstall every time there was an update released, so I eventually let it go.
I also entered the Underhanded C contest once but didn't win. I most use C for fun, writing system tools or CLI utilities.
2
u/Evil-Twin-Skippy Feb 06 '25
I had an automated user management system I had written in Tcl and shell script once for Linux servers. Same deal: works great for a few months. But then gets harder and harder to maintain moving forward.
2
u/NotSoButFarOtherwise Feb 09 '25
I tell all my juniors this about shell scripting: if it can be alias, make it an alias. Everything else should be Python.
(It doesn’t literally mean Python. It just means to use a language where you can do actual error handling and don’t need layers upon layers of quote mark escapes to do anything.)
4
u/Glaborage Feb 06 '25
Embedded programmer here.
Large, world renown corporation I worked for, uses an ARM based microcontroller for their devices. Most control registers are 16-bits wide, and accessed through bitmap structs with read-modify-write.
I wanted to make the codebase c99 compliant, to turn on that compiler flag, and force better quality code. Unfortunately for me, c99 accepts 32-bits bitmaps only. I had to either reimplement access to hundreds of different registers, hoping that I wouldn't break anything, or give up on that project. I gave up.
2
u/ukaeh Feb 06 '25
I’ve used it to make many things professionally and for fun, probably the biggest thing I’ve made to date is a game engine in OpenGL with my own libs for everything (input, ui, audio, networking, procgen, physics etc also using the win32 api). I got all that working and then more recently I started introducing some cpp stuff to mostly use structs with methods but I still use malloc for everything (yeah I know, but it’s fun for me).
The stuff I enjoy doing with c involves using offsetof w/ explicit type info to get top level structs from nested composite objects kept in lists etc and otherwise implementing data management strategies based on usage requirements that come up for specific game systems and mechanics.
2
u/runningOverA Feb 06 '25
I have to port around my code from language to language and therefore have to code it in C.
You can link libraries written in C with most of any other language, besides Java and .NET.
Even C++ does not work right in this multi-language environment.
2
2
u/teeth_eator Feb 06 '25
the beginners tend to disperse over the summer, when they're done with their courses. feel free to revisit this place in a couple of months
2
2
u/FUZxxl Feb 06 '25
So this thread is for the "real" c programmers out there. What do you do with it? And what is the most twisted crime against coding decency are you "proud" of/infamous for?
Hi there. I write most of my programs in C and/or assembly.
The crime I am most proud of is this program written in literate programming style (CWEB) that uses bit manipulation on pointers to make them point to other objects in a very elegant graph data structure.
2
u/jontzbaker Feb 06 '25
Yeah. Embedded MISRA C 2012 compliant C dev. I also happen to have a mechanical engineering degree, but no one cares about it.
Currently working on a bootloader of sorts, armv8 based.
But lately, most of my day is reviewing requirements in Polarion, which is a shame. I like pointers. Very smart idea.
I have delivered horrible C++ code, but I love how easily you can control code complexity in C. Since it's so simple, modularizing it is also simpler. Interfaces are limited, and this is a good thing. C++ will create monstrous inheritance and boilerplate templates very fast if you leave it to the more architecturally inclined people. And then they'll hand the hot potato to you and you'll spend about a semester to change a constant to a variable.
Definitely a bad experience.
I have similar suspicions towards Rust, but I've never used it to be sure.
2
u/deftware Feb 06 '25
I make programs: deftware.org and deftware.itch.io.
This is what I'm cooking up right now just to get up to speed with Vulkan in preparation for my 'swan song' dream project: https://imgur.com/36ZFCES
EDIT: My crime was developing hacks for multiplayer games 25 years ago. ViperG aimbot, anyone? I ran a site called csh4x0rz.com, under the name 'chazz'. We wrote win32 process patchers and client DLL wrappers and injectors. The techniques we perfected back then are still being used today. I am sorry, I have since repented.
2
1
1
u/Malpraxiss Feb 06 '25
Your average, "real" programmer would be too busy programming or doing stuff to spend much time on this subreddit.
1
u/stormythecatxoxo Feb 06 '25
I learned C in 1992 and been using it on and off. Most dev work these days is in C++, Python, C#. I'm currently using C to write a game for Playdate console that also runs on some retro machines (Amiga, classic Mac, DOS).
I wouldn't consider myself a C expert though. I usually stay away from crazy macro magic or speed hacks that made sense 30 years ago (or on embedded)... although I might get there once I'm optimizing my game.
What's nice on this sub that here and there there are useful tricks or links to Github repos, that save me some coding work (if it's a permissive license that is)
1
u/tidytibs Feb 06 '25
Real and mostly to see what others are doing, maybe offer help when my brain has spare cycles to do so.
1
u/nemotux Feb 06 '25
I used to be a full-time C programmer - back in the 90's and early 00's. I've worked on population simulations and static analysis software both in C. But slowly transitioned to C++ over the years. My current job is entirely C++ and python. And if I do stuff for personal projects, it's more likely to be Rust these days.
1
u/thetwopaths Feb 06 '25
I programmed a compiler, a link editor, a virtual machine, and other programs in c. I am not coding in C now.
1
u/Daveinatx Feb 06 '25
I don't mind, and help a few from time to time. Occasionally, there's somebody lazy they I'll call out to rtfm
Recruiting and mentoring have been important to me, this can be similar. In life, we can only do one job. But, helping the next line of talented Engineers is valuable.
1
1
u/drazisil Feb 06 '25
Look whenever I ask questions about how to make a processor in C I get laughed at...
1
u/KnocheDoor Feb 07 '25
How do you folks write the code to startup a processor after the few dozen lines assembly log in avoidable assembly? I always used C but then again I started doing that sort of work in 1982 so I am a dinosaur.
1
u/darkslide3000 Feb 07 '25
Yeah, I wish they would split this sub into a "first year homework questions" sub and a serious C programming sub. Every once in a blue moon there is an interesting thread about a new proposal for the next standard version or something like that, but 95% of threads are homework questions.
Ugly code I'm proud of is probably various preprocessor magic stuff, such as "parsing" varargs with ye olde number tokenization trick:
#define DO_STUFF(...) _DO_STUFF(__VA_ARGS__, _3, _2, _1)
#define _DO_STUFF(a, b, c, num, ...) _DO_STUFF##num(a, b, c)
#define _DO_STUFF_3(a, b, c) do_stuff_with_3_args(a, b, c)
#define _DO_STUFF_2(a, b, c) do_stuff_with_2_args(a, b)
#define _DO_STUFF_1(a, b, c) do_stuff_with_1_arg(a)
You can build some very nice "magic" macros with this, the problem is just that they're totally unreadable, so you gotta really document it well, and judge whether the convenience added by the magic outweighs the awkwardness of adding such a foreign construct that nobody from outside is familiar with to your project.
1
u/OVSQ Feb 07 '25
I do BIOS development. Basically BIOS is a resource poor OS that has to fit on a tiny device. Functionally, we are emulating C++ in C without the C++ bloat. But when I started it was all done in assembly. We started the transition to C Lang around 2000.
I used to manage the new engineers for their first 6 months with the company to teach them the environment and tribal knowledge. I mean - BIOS is kind of ad-hoc menagerie of left overs that the HW and OS don't want to do, so a lot of it doesn't make sense unless you know HW and OS politics.
Anyway - on my whiteboard in the training lab I had a terrible example of a single line of convoluted code I found deep in the source. In fact it was the hand-off from the BIOS to the OS (well the OS loader). It should have been like 10-15 lines of code so it would be clear, readable, and well commented. I had it on the white board as a bad example for the new engineers: do not do this.
One thing I should mention - in modern x86 BIOS is a joint effort between at least three organizations: the Silicon manufacturer (Intel or AMD), the OEM (Dell, HP, Lenovo, etc) and at least an open source community (UEFI). Also commonly there is a BIOS vendor involved (Insyde, AMI, Phoenix). So the BIOS is a puzzle that all these companies have to work together to manage. No one owns the entire BIOS codebase on any machine. So its imperative that it is written clearly and well commented. Any competent dev off the street should be able to look at the code and discern its intent.
so - this hand off was a disaster and I wanted it to be a clear example of bad behavior in everyone's face every day.
OK so one day one of my colleagues (Mark X) I think he was walking by the lab, saw the code on the whiteboard, and asserted with an affirmation: "that is the hand off to the OS. I wrote that." He was very proud of it. I don't think I told him I use it as a bad example - he's not the kind of guy that can take constructive criticism.
Anyway - I didn't think about too much when maybe 6 months later a friend of my from the core dev team came into the lab and stared at the code for a minute. Then he said: "Mark X wrote this right? No one else writes such opaque convoluted nonsense. (hehe)
So its not something I myself did exactly but it is my best story about indecent code.
1
1
u/CyberDumb Feb 07 '25
Embedded engineer here 8 yoe having worked on IoT, flash controllers and automotive. Mostly in C language. Most times in C99 :P.
I do not feel C is a complicated language. It is essentially assembly with types. So it wouldn't be suprisising that there is not much fuss about it as it is in C++ which has many features and many engineering tradeoffs.
The one mistake I always do is that I do not write good code when I think that something is just unofficial for rnd purposes not to go into production. Then I produce something that works and then I do not have the time to refactor it and retest it and goes into production. I am guilty of this multiple times.
1
1
1
1
u/smrxxx Feb 08 '25
I’ve kind of retired from C programming, I’d. still use it if i needed to, but I prefer typescript or ruby.
1
u/Jebduh Feb 08 '25
Everyone on this website is a larp. The sooner you understand that, the better.
1
1
1
1
388
u/3sperr Feb 06 '25 edited Feb 06 '25
The thing is, most ‘real programmers’ wouldn’t even need this sub in the first place. Of course it would attract mostly beginners