I've not been a subreddit moderator before, but I love C and am willing to commit to this.
As for my intentions for this subreddit, I would like to see it become a home for everything and anything related to C programming that's interesting. I would delete posts about simple problems, but I think interesting problems (like the top questions on StackOverflow) could be kept.
I would otherwise try to take a very hands-off approach to moderation, but if the community compels me to address another problem that voting can't address (e.g. blogspam?) I will. I will likely consult the community before deleting other content.
I'm interested in persuing a number of experiments and initiatives, depending on how the community feels about them, like:
If someone else wants to campaign for moderator, may I ask that you first support me in getting the Reddit admins to hand over moderator to me; I suspect that ambiguity or dispute will harm our case. Then, if community support is in your favor, I will grant you to be moderator and remove myself.
Chapter 7 of the Linux Coding Style explains using goto
for cleaning up before returning from functions.
>Chapter 7: Centralized exiting of functions
>Albeit deprecated by some people, the equivalent of the goto statement is >used frequently by compilers in form of the unconditional jump instruction. > >The goto statement comes in handy when a function exits from multiple >locations and some common work such as cleanup has to be done. If there is no >cleanup needed then just return directly. > >The rationale is: > >- unconditional statements are easier to understand and follow >- nesting is reduced >- errors by not updating individual exit points when making > modifications are prevented >- saves the compiler work to optimize redundant code away ;)
int fun(int a) { int result = 0; char *buffer = kmalloc(SIZE);
if (buffer == NULL) return -ENOMEM;
if (condition1) { while (loop1) { ... } result = 1; goto out; } ... out: kfree(buffer); return result; }
Heh, I'm not sure if this is a joke, though it's certainly a fun thing to think about - a detail I've always wanted to stick in a sci-fi story is a math professor who releases a publication via its index of Pi and size.
For those who thought about this for a while and aren't sure why it wouldn't work (besides because of the theoretical issue they brush aside in the description, which is that Pi is not proven to contain all permutations of numbers), the problem is the size of the indexes you need to store in combination with the pidgeonhole principle. For example, if you wanted to store all the numbers from 00..63 in pi, and Pi happened to be ordered such that it was:
0001020304...
You would have 63 numbers, but would need to index up to 118 spots - that is "00" is two spots, "01" is an additional two spots, etc. - and "63" is 116 spots in! So, all of a sudden, in order to index 63, you need an additional digit, increasing the size of your data instead of shrinking it.
This comment on Hacker News shows a basic example; the tl;dr is that, on average, the number of bits you need to store the index of pi for your data is a larger number than the data itself.
That said, you can store some things well, things that have a lot in common with pi at early indexes of pi. And of course, you have infinite compression of Pi. :P
If your logs are in some well defined format, it should be possible to aggregate the log files. Popular technologies for this are
I haven't set up anything like this myself, but I'm a happy user of a system built on the ELK stack.
You can find more info by searching for "how to set up aggregated logging"
Also, TCC is specifically designed to do this sort of thing. It's a very fast compiler, too, though the executable won't run nearly as fast as GCC's output.
#!/usr/bin/tcc -run #include <stdio.h> // ...
My harddrive is littered with half-abandoned projects. These are the ones I've currently working on (all in C89):
As for quality, I quite like the sqlite approach. That is, extensive testing and verbose inline documentation
I don't think even a half of these are "evil C".
Logical XOR is just that. If you need a logical xor, !a != !b
is a correct solution. https://stackoverflow.com/questions/1596668/logical-xor-operator-in-c mentions this, but pay attention to the second-top answer which talks about sequence points.
The "goes toward" operator is something I've seen pop up here and there. It's not a very common idiom but it should be understandable. It might go against certain formatting standards, though.
Optimization, the Microsoft way is just derp.
Duff's Device is a very old construct that shouldn't be used any more. Your compiler can/will do it for you, so leave your loops clean.
Struct/class offsets is pretty straight-forward, if you care to read it. It casts 0 to a pointer to the struct, and then casts the pointer to the requested field to int. That gives you the offset of that field. Nothing "abusive" or "evil" here, IMHO it's the obvious solution. You should probably just use offsetof
from stddef.h
, though.
if ((x | y) < 0)
might be a bit terser than what some programmers are used to, but to me it's quite readable. The meaning is clear, and if it's not obvious right away, it doesn't take a lot of mental gymnastics to figure it out (and then you sigh how clever this is and wonder whether you should start using it too).
[] is symmetric is one of the first things you learn in any C book and course. The snippet of code might be a bit more clever than what it's worth, though. "nsew"[direction]
is probably something you'd see more often.
snoob
might take a bit longer to understand, but the comment shows you how it works by giving an example. Once you do understand it, it seems like an obvious non-brute-force solution (the brute-force solution being incrementing the input and counting bits).
I won't comment on the floating-point and comment abuses because those really are evil.
Here's an extract of one of my previous comments with regards to this website:
> I'm not going to bother correcting all of your errors. It'd be less wasteful of my time to simply write my own textbook, and to be clear on that matter, there's nothing wrong with K&R2E. Your website exists without a purpose, and lies to people. What you should do, to be honest to your students and to the founding forefathers of the language, is redirect your entire domain to the Amazon page for K&R2E. Make an affiliate link, if you like, so that you get commissions on the sales... at least this way your students will learn the **actual* programming language, as opposed to your retarded imagination of it*.
Shame on you, you should know better as a professors assistant.
There-in lies the flaw in your reasoning; you're looking online for an educational resource for an authoritatively defined programming language... and any moron can post rubbish online. To be clear on that, I'm also a moron... but I at least strive not to mislead people, where-as the author of this website doesn't give a crap. It seem he'll publish any nonsense, without learning, probably just to make himself look credible (even if the rubbish is misleading and the publishing of it is possibly illegal). I think maybe he's a sociopath, grooming his image as an educator at a university who has taken it upon himself to needlessly (and horrifically) reinvent the wheel of education.
Over the decades, K&R2E has taught many thousands of people the bulk of what we know as C without serious problems. Save yourself many headaches, request a copy at your library if you can't afford it... read through it, do the exercises as you stumble across them, and feel free to ask the people here if you have any problems with those exercises (don't skip exercises in this textbook). I have confidence that everyone here (except perhaps u/WesternLong) will honestly try to help you if they can. What they won't do is needlessly reinvent the wheel of education (or at least, so I hope), for like me, many of these people likely see no significant improvement that can be made upon the authoritative resources we used to learn.
The way you're going about it now, though, you'll stumble across this problem again and again: the idiots of the internet who assume the role of an educator without properly learning C, presumably in order to groom their own self esteem...