ioccc | My IOCCC submissions and practice | Math library
kandi X-RAY | ioccc Summary
kandi X-RAY | ioccc Summary
2020-minimd5 An MD5 tool, with 64x4 byte constant table generation using integer arithmetic. 2020-rectangles Represents an image with the number of rectangles. 2020-lettermixer Randomizes the order of letters in words other than the first and last. 2020-markovchain Generates random text based on a dictionary using a Markov chain. One entry in 2020 did not win, will be reworked for next year's contest.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of ioccc
ioccc Key Features
ioccc Examples and Code Snippets
Community Discussions
Trending Discussions on ioccc
QUESTION
This is a purely theoretical question here (though one I think is an interesting thought exercise). I was just working on a JavaScript object (documentation-related) and the somewhat-unusual thought crosses my mind: is there a way to make a key/value pair entry within said object capable of reading its own key as part of its value? That is to say:
Assuming I have a JavaScript object used for the purposes of serializing data:
...ANSWER
Answered 2020-Nov-17 at 14:01This is probably the most surefire way to do it. When obj.foo()
is called, then foo
is executed with obj
set as the value of this
. This means that we can lookup the key from this
. We can examine the object easily the hardest thing is to find which key contains the function we just executed. We can try to do string matching but it might fail for:
QUESTION
The carefully crafted, self-including code in this IOCCC winning entry from 1988:
http://www.ioccc.org/years.html#1988_isaak
...was still too much for certain systems back then. Also, ANSI C was finally emerging as a stable alternative to the chaotic K&R ecosystem. As a result, the IOCCC judges also provided an ANSI version of this entry:
http://www.ioccc.org/1988/isaak.ansi.c
Its main attraction is its gimmick of including in the last line (!) with well-thought-out
#define
s, both inside the source and at compile time, to only allow certain parts of the code into the right level. This is what allows the header to be ultimately included at the latest stage possible, just before it is necessary, in the source fed to the compiler.
However, this version still fails to produce its output when compiled today, with the provided compiler settings:
...ANSWER
Answered 2020-Oct-11 at 10:37There is nothing remotely portable about this program. As I see it tries to overwrite the exit
standard library function with its own code, expecting that return from empty main()
would call that exit()
, which is not true. And even then, such behaviour is not standard-conforming - even C89 said it would have undefined behaviour.
You can "fix" the program on modern GCC / Linux by actually calling exit();
inside main
- just change the first line to
QUESTION
Another pearl from the early IOCCC years is Larry Wall's 1986 entry:
http://www.ioccc.org/years.html#1986 (wall)
I suspect there is no C compiler today that can actually compile that source straight-out-of-the-box, due to the severe preprocessor abuse it contains:
- Latest
TDM-GCC 9.2.0
set to ANSI mode fails - Last
TCC 0.9.27
fails
However, after wrenching the preprocessed code out of the obfuscated original (always with GCC's cpp -traditional
), both TCC and GCC manage to compile it; nevertheless, GCC's effort goes to waste as the program chokes when trying to begin decoding its obfuscated intro text (not going to spoil that here for those who want to delve themselves!)
TCC, on the other hand, manages to summarily warn about implicit declarations of system()
, read()
and write()
and quickly produce a working program.
I tried to step through the GCC code execution with GDB and that's how I found that the compiled GCC code chokes on the second pass of a for
loop that goes through a text string in order to decode it:
[Inferior 1 (process 9460) exited with code 030000000005]
That process ID doesn't matter as it represents the debug build executable that crashes. The exit code, however, stays the same.
Clearly, TCC is better suited to such IOCCC entries that GCC. The latter still manages to successfully compile and even run some entries, but for tough cases like this one, TCC is hard to beat. Its only drawback is that it falls short when preprocessing extremely abusive code such as this example. It leaves spaces between certain preprocessed entries and thus fails in concatenating them into the author's intended C keywords in places, whereas GCC's cpp
works 100%.
My question is, as philosophical or even rhetorical as it sounds:
What is it in modern GCC that makes it either fail to compile, or produce unusable code when it does compile, earlier C programs, unlike TCC?
Thanks in advance for all the feedback, I appreciate it!
NOTE: I am using Windows 10 version 2004 with WSL 2; GCC fails in both the Windows and the WSL 2 environments. I am planning to compile TCC in WSL 2 for comparisons in that environment too.
PS: I immensely enjoyed this program when it finally executed as intended. It undoubtedly deserves that year's "grand prize in most well-rounded in confusion"!
...ANSWER
Answered 2020-Oct-04 at 22:04The crash is caused by the program writing to the contents of a string literal. "Traditional" C compilers would often put these in writable memory, but on modern systems they're basically always in read-only memory. I'm surprised it doesn't crash with TCC.
Here is a version of the program that compiles without complaint with GCC on my computer (even with a very high level of warnings) and appears to work correctly. I have made as few changes as possible. As usual with the best IOCCC entries, preprocessing and reformatting barely helped at all, although they did remove some traps for casual reverse engineers.
The program assumes system
invokes a Bourne-style shell, and a Unix-style stty
command is available to that shell. Also, it will malfunction (probably in an amusing fashion) if the execution character set isn't ASCII.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install ioccc
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page