As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
A professor of mine has said he'll accept homework assignments in any language we'd care to use. I'm on good enough terms that I'd like to mess with him a bit and submit a valid homework assignment using brainfuck, whitespace, or some equally "useful" language.
I have the C-sources for a few simple numerical analysis routines as well as the compiled output and the assembly files they generate.
Does anyone know of a decompiler (or a C->brainfuck translator) that could give me something akin to the "brainfuck source code"?
Just use APL or J.
Unlike BF, they were actually designed to serve a "useful" (and not a "useful as in BF" sense) purpose - and yet can easily make Perl code-golf entries look like novels. (The dedication and mental training to enjoy these languages is currently more than my skill/effort levels.)
If the goal is using a purely esoteric language, I have always enjoyed the look of Piet programs. It looks prettier and is actually able to solve common CS homework problems. Following the links will reveal "Piet assemblers" and other tools. Win.
Happy coding.
For what it's worth, I just wrote a very simple Brainfuck Assembler (inspired by this SO post actually), which assembles readable source code (not C, just something simple and nameless) to BrainFuck. The source-code and compilation/usage instructions can be found here: BrainFuck Assembler.
Edit: The project has recently been updated under a new name: BrainFix.
Edit 2: I redid the entire project. The new and improved version has quite a lot of features and is available on Github.
A quick Google search brings up the (a?) Brainfuck site, which links to an archive with "all things Brainfuck". I doubt there's a C->brainfuck translator anywhere, I wouldn't think anyone would invest that much time.
Related
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
I am fascinated by the way people obfuscate their code (mostly, C) (examples here : http://ioccc.org/) and would like to learn the various techniques for the same. I have been told of a book, "Obfuscated C and other Mysteries", but I am not able to get that book.
Are there any tutorials or books that give hints on this topic?
Thank you.
The best you can do is read the comments of the author of the programs on IOCCC. They describe how they manage to obfuscate their code. Here are a few pointers:
Short and meaningless identifiers
Because a=aaa*aa; will always be more obfuscated than result = value * factor;
In order to have short identifiers, obfuscators tend to even #define many things.
Reversed array indexing
You just have to remember that var[3] and 3[var] are equivalent.
Digraphs and trigraphs
if(a< <:b+aa??))??<f();%>
should be less readable than:
if (a < (b+aa)) { f(); }
Look-alike characters
Sometimes, it's hard to tell appart l, 1 and I or o, 0 and O. For example, if you write 10l, I bet everyone will read 101 instead.
Coding style guidelines
Generally speaking, just try to find good coding guidelines and to try to violate them all. Those documents that you could find anywhere on the web could help you more than most things and would allow you not to buy anything.
Here are some links:
How to write unmaintainable code.
Morwenn's answer nicely covers obfuscation of syntax. But there is another level, and that is semantic obfuscation. Consider that the oft-mentioned Turing Machine has the same computational power as any other programming language (ignoring considerations of input and output). In fact all of the various models of computation have sibling models with equivalent power.
For example, a string char s[N] can be considered a mapping from indices to characters, so any string can be represented instead by a function which always delivers the appropriate character when called with a specified index char f(int i). Now read this. Crazy, right?
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I know it sounds kind of subjective, but I want to implement basic library functions in C in order to gain better understanding in C (mostly in pointers) and improve my skills, since I'm only a beginner (in C & programming in general).
I also find it useful since you get to understand better what happens behind the scenes and how those basic functions work.
Which basic C library functions can I implement? I'm looking for simple ones like strcpy, atoi, strstr that are not too complicated (I'm only a beginner) but still require some thinking.
Strings function are always challanging (and required). Try split a string to tokens, join strings, replace string in strings. Believe me, after that not only you will be a better C programmer, you will also appreciate open source libraries! (and C++ STL..)
Good luck!
After having implemented strtok(), you may want to switch to next level with qsort() and its function pointer.
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
Wikipedia defines reflection as follows:
In computer science, reflection is the process by which a computer
program can observe (do type introspection) and modify its own
structure and behavior at runtime.[1]
Is there any major programming language (widely used in Academia or Industry) that doesn't support any form of reflection? All the examples I'm currently thinking of have at least limited support. But for C I'm for example not sure.
C, C++ dont have any forms of reflection. What can be done is embed debugging symbol in the executable with the compiler, and then process the symbol table from within the executable. However, this process must be implemented by the code (i.e. write code in c to break down and process the symbol table in the executable). Therefore, it isn't inherent in the language.
COBOL is a major language that does not. Nor any of the HDLs (VHDL, Verilog, ...).
I think a more interesting question is, what languages have complete access to their structure by "reflection"? (e.g, "what in this expression?" "What's the type of that expression?" "Build me a new class.", etc.) AFAIK, only LISP meets this requirement. Other languages provide some reflection at best but cannot entirely manipulate those langauges.
That leaves the question as to why one would add only partial reflection to a language. We make our languages Turing capable so that if we want to code something, we're pretty sure we can code it in our language. Why aren't our languages correspondingly "full reflection" capable?
One way out of this is to use program transformation systems (PTS), which are tools designed to manipulate code. A truly generic PTS (such as Stratego, DMS or TXL) can manipulate arbitrary programs in arbitrary way, providing what amounts to "full reflection". This allows one to do metaprogramming on arbitrary languages; you don't have to depend on your language committee or your compiler vendor to add bits and pieces of reflection capability.
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
I relearning C; it's been years and whilst familiar the nuances are lost in time.
I originally learned C from K&R. However, I now see many people levelling criticism at K&R.
A chief example is http://c.learncodethehardway.org/book/learn-c-the-hard-waych55.html#x61-27200055
Top reasons seem to be that it's code style is overly terse, practises aren't applicable in larger programs and lead to memory leaks or are subject to attack in shared network accessible systems.
Do people feel these criticisms are fair? Do they matter to somebody learning C? If so, could people recommend a "modern" C book, preferably available for Kindle?
As long as you're talking about the 2nd Edition, K&R is still very relevant.
In fact, I would say it's still the very best single book on C, both for learning, and for reference.
That said, you should also get a copy of Harbison & Steele's "C: A Reference Manual". It's the best current reference on C, and the Fifth Edition covers C99, which you should use if you can.
Also, once you've got a bit of C behind you, I'd strongly recommend reading "Expert C Programming", by Peter van der Linden.
It is still relevant and still very useful with regards to learning the language. Learning the language doesn't require you to implement new practices or styles that assist in code readability, etc.
For example, the idea of self documenting code is that you use verbose variable and function names to help explain the purpose of a function or a variable. K&R is clearly opposed to this. That doesn't mean you can't learn the C language from K&R, it just means that your style will need to be adjusted/updated based on whatever naming convention you decide upon in the future.
I cannot recommend "Expert C Programming" enough (as stated by gregj).
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I'm looking for interesting programming puzzles, problems or challenges suitable for a class of chemistry majors learning C as their first programming language. Do you have any recommendations?
Project Euler is pretty good. They have some simple challenges that may be suitable.
These won't really do much to teach them C, though. Text books are much better for that.
Additionally, you could have them write a program to balance chemical reaction equations. That would be good for I/O and simple math.
Given a text file with a whole bunch of pressure/temperature/mole count as input, and using the ideal gas law equation, output the values of the volume for the gases and output the entire set of data (P,V,T and n) into a nicely formatted output file.
Should cover file i/o, basic function usage, and string formatting. Has the potential to cover arrays and stucts as well.
David, tasks that come to my mind would be:
calculation of the number/topology of isomers of hydrocarbons (cyclic and acyclic, saturated and unsturated)
numerical integration of optical spectra (absorption and fluorescence)
kinetical models
deconvolution of experimental data
modelling of thermodynamical cycles and their efficiencies
This seems a really vague question but assuming I'm a chemistry student that is learning C I would like to write programs that allows me to define molecules and compounds starting from simple elements.
I really don't know how to explain it, but maybe define your struct for a nitrogen atom, one for oxigen atom and have a way to bind it to produce water.. or maybe mixing to different substances too see what will come out programmatically..
You can try pex4fun. It allows you to learn algorithms in C# (which is close enough to C). pex4fun provides read-to-use classes and also engaging coding duels that turn learning into a game.