Real Programmers Don’t Use Structs


 1 /* Behold, the Holy Grail of low-level procedural
 2 programming...
 3 
 4 The essay Real Programmers Don't Use Pascal tells
 5 of Real Programmers who are able to code complex
 6 data structures and algorithms without the aid of
 7 objects, structs, or similar high-level aggregate
 8 data types.  Real Programmers, according to the
 9 mythos, are able to program using arrays as their
10 only aggregate data type.
11 
12 This program creates two "structs" which are really
13 flat arrays.  The fields are all void pointers -
14 the most powerful scalar data type in C which can
15 be used to encode any other scalar type - either
16 regular data or pointers.  A link is created
17 between the two nodes, forming a minimal link list,
18 and the linked list is traversed and the content
19 fields outputted and operated on, to make sure they
20 are fully functional.
21 
22 I am very excited to say that this experiment was
23 a complete success.
24 */
25 
26 #include <stdio.h>
27 #include <stdlib.h>
28 
29 int mainint argc, char **argv ){
30         void *head[2];
31         void *tail[2];
32         head[1] = &tail;
33         head[0] = (void *) 25;
34         tail[0] = (void *) 50;
35         printf"%d\n", (int64_t) head[0] + (int64_t) tail[0] );
36         void **cur = head;
37         printf"%d\n", cur[0] );
38         cur = cur[1];
39         printf"%d\n", cur[0] );
40         return 0;
41 }

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s