Question
How sykes2.c Works: Explaining an Obfuscated C Program That Prints __TIME__
Question
How does this C program work?
main(_) {
_ ^ 448 && main(-~_);
putchar(
--_ % 64
? 32 | -~7[__TIME__ - _ / 8 % 8][">'txiZ^(~z?" - 48]
>> ";;;====~$::199"[_ * 2 & 8 | _ / 64]
/ (_ & 2 ? 1 : 8) % 8 & 1
: 10
);
}
It compiles as written and prints the compilation time as large block-style digits based on the __TIME__ macro. For example, it can produce output like this:
!! !!!!!! !! !!!!!! !! !!!!!!
!! !! !! !! !! !! !! !!
!! !! !! !! !! !! !! !!
!! !!!!!! !! !! !! !! !! !!!!!!
!! !! !! !! !! !! !!
!! !! !! !! !! !! !!
!! !!!!!! !! !! !! !!!!!!!
The main goal is to understand the ideas behind this code: recursion, implicit int, unusual array indexing, use of __TIME__, bit manipulation, and how the expression inside putchar() decides whether to print a space, !, or a newline.
Short Answer
By the end of this page, you will understand how an obfuscated C program can generate output from a compile-time string using recursion and bit operations. You will see how sykes2.c uses __TIME__, strange-but-valid indexing like 7[array], character arithmetic, and a compact bitmap technique to draw large digits one character at a time.
Concept
What concept is this code teaching?
This program is mainly about decoding dense C expressions. It combines several core C ideas:
- Recursion to simulate a loop
- The
__TIME__predefined macro to get the compile time as a string like"12:34:56" - Array indexing equivalence:
a[b]is the same as*(a + b), so7[s]is valid C - Bit manipulation to store and read pixel patterns for digits
- ASCII character arithmetic to turn bit results into printable characters
- Short-circuit logic and the conditional operator
?:
Why this matters
Obfuscated code is intentionally hard to read, but learning to unpack it helps you build real skills:
- reading unfamiliar legacy code
- tracing expressions carefully
- understanding operator precedence
- recognizing when code is using compact data encodings
- separating what a program does from how strangely it is written
What the program is really doing
At a high level, the program:
- Counts through positions in a 7-row text grid
- Decides whether the current position should be a newline or a visible character
- Maps each text cell to one of the 8 characters in
__TIME__
Mental Model
Think of this program as a tiny printer head moving across a rectangular banner.
- The banner has 7 rows.
- Each row contains spaces and
!characters. - The program moves through the banner one cell at a time.
- For each cell, it asks:
- Is this the end of the line? Print
\n. - Otherwise, which character of
__TIME__am I drawing here? - Which row of that digit am I in?
- Does that pixel need to be on or off?
- Is this the end of the line? Print
If the pixel is on, it prints !.
If the pixel is off, it prints a space.
A good analogy is a dot-matrix sign:
- the compile time string is the text to display
- the encoded strings are the font data
- the bit shifts and masks are how the program checks whether one dot should light up
Syntax and Examples
Core syntax pieces used in this program
1. Recursive countdown or count-up trick
void f(int n) {
if (n < 5) {
f(n + 1);
}
printf("%d\n", n);
}
This calls itself before printing. The obfuscated program uses the same idea, but much more compactly:
_ ^ 448 && main(-~_);
Explanation:
-~_means_ + 1_ ^ 448is zero only when_ == 448A && BevaluatesBonly ifAis nonzero
So this means roughly:
if (_ != 448) {
main(_ + 1);
}
2. a[b] is the same as
Step by Step Execution
A smaller traceable fragment
The hardest part of sykes2.c is that everything happens in one expression. So first, isolate the control flow:
main(_) {
_ ^ 448 && main(-~_);
putchar(--_ % 64 ? 'X' : '\n');
}
This is not the original output logic, but it shows the order clearly.
What main(-~_) means
-~_
Bitwise NOT flips bits, so:
~xis bitwise NOT-~xis a well-known trick forx + 1
Example:
- if
_ = 5 ~5 = -6-(-6) = 6
So main(-~_) means main(_ + 1).
What _ ^ 448 && main(-~_) does
Real World Use Cases
Why learn from code like this?
You would not write production code in this style, but the underlying techniques are useful.
1. Reading compact encodings
Real programs often store data in compressed or packed form:
- bitmap fonts
- image masks
- protocol flags
- hardware register values
- feature bitsets
This program is effectively reading a tiny packed font.
2. Understanding generated output
Many tools create text output from data:
- CLI dashboards
- ASCII charts
- terminal clocks
- log formatting tools
- status displays in scripts
The program turns a string into a formatted text banner.
3. Working with compile-time macros
Predefined macros like __TIME__, __DATE__, and __FILE__ are often used for:
- build information
- debug output
- version banners
- generated metadata
Example:
printf("Built at %s on %s\n", __TIME__, __DATE__);
4. Operator precedence awareness
Even if you never write code like this, you must be able to read expressions involving:
Real Codebase Usage
How developers use these ideas in real C projects
Guard clauses and readable control flow
Instead of this obfuscated recursion:
_ ^ 448 && main(-~_);
real code would use a loop or a clear base case:
for (int i = 0; i < 448; i++) {
/* print one cell */
}
or
if (i == limit) return;
Validation and explicit declarations
Production code should include headers and types explicitly:
#include <stdio.h>
int main(void) {
puts(__TIME__);
return 0;
}
Packed data tables
Developers do use packed tables, especially for:
- embedded fonts
- lookup tables
- state machines
- parsers
- codecs
But they are usually written with names and comments:
Common Mistakes
1. Thinking 7[s] is invalid C
Broken assumption:
char *s = "abc";
/* many beginners think this is illegal */
printf("%c\n", 1[s]);
It is valid because a[b] means *(a + b).
2. Forgetting that old C allows implicit int
This program uses:
main(_)
In modern C, you should write:
int main(void)
or with parameters:
int main(int argc, char **argv)
Relying on implicit int is outdated and nonportable.
3. Misreading -~x
Comparisons
Obfuscated style vs readable style
| Topic | Obfuscated version | Readable version |
|---|---|---|
| Increment | -~x | x + 1 or ++x |
| Equality check | x ^ 448 equals 0 | x == 448 |
| Conditional execution | cond && action() | if (cond) action(); |
| Newline | 10 | '\n' |
| Array access |
Cheat Sheet
Quick reference
Weird syntax used in sykes2.c
-~x // x + 1
x ^ y // bitwise XOR
a && b // evaluate b only if a is true
cond ? A : B
7[s] // same as s[7]
32 | bit // 32 if bit=0, 33 if bit=1
Useful facts
__TIME__is a string literal like"14:53:07"putchar('\n')andputchar(10)both print a newlinea[b]means*(a + b)x >> n & 1extracts one bit
Structural constants in this program
- 8 characters in
__TIME__ - 8 columns per character block
- 64 columns per line
- 7 lines total
- 448 total output positions
Readable rewrites
_ ^ 448 && main(-~_);
becomes
FAQ
Why does 7[__TIME__ - n] work in C?
Because array indexing is defined as pointer arithmetic: a[b] means *(a + b). So 7[s] is the same as s[7].
What does -~_ mean in C?
It is a trick for _ + 1. The bitwise NOT and unary minus combine to produce the next integer.
Why does the program use recursion instead of a loop?
Mostly for obfuscation. It behaves like a loop over 448 output positions, but recursion makes the code look stranger.
What is __TIME__ in C?
__TIME__ is a predefined macro that expands to the compilation time as a string in the form "hh:mm:ss".
Why does the code print ! instead of solid blocks?
Because it maps a single extracted bit to either ASCII 32 (' ') or ASCII 33 ('!').
Is this valid modern C?
Not really as good modern style. It may still compile with some compilers, but it relies on outdated features like implicit and missing function declarations.
Mini Project
Description
Build a small C program that prints the compile time (__TIME__) as large text using a readable 2D font table. This project demonstrates the same core idea as sykes2.c—turning a string into banner output—but without obfuscation. You will practice loops, indexing, compile-time macros, and simple bitmap rendering.
Goal
Create a readable C program that prints __TIME__ in a 7-row block font using spaces and ! characters.
Requirements
- Use
__TIME__as the source text. - Print the output as 7 rows of large characters.
- Support digits
0through9and the colon:. - Use loops instead of recursion.
- Print spaces for empty pixels and
!for filled pixels.
Keep learning
Related questions
Building More Fault-Tolerant Embedded C++ Applications for Radiation-Prone ARM Systems
Learn practical C++ and compile-time techniques to reduce soft-error damage in embedded ARM systems exposed to radiation.
Definition vs Declaration in C and C++: What’s the Difference?
Learn the difference between declarations and definitions in C and C++ with simple examples, common mistakes, and practical usage.
Difference Between #include <...> and #include "..." in C and C++
Learn the difference between #include with angle brackets and quotes in C and C++, including search paths, examples, and common mistakes.