Explorar el Código

C: The ancient one.

I should also add that Hello World in assembler, though. And add some
less mainstream languages to this thing. It's getting kind of boring. :)
Lucas Stadler %!s(int64=12) %!d(string=hace) años
padre
commit
2b57917540
Se han modificado 3 ficheros con 41 adiciones y 0 borrados
  1. 4 0
      c/Makefile
  2. 7 0
      c/README.md
  3. 30 0
      c/anon_struct.c

+ 4 - 0
c/Makefile

@ -0,0 +1,4 @@
1
all: anon_struct
2
3
anon_struct: anon_struct.c
4
	gcc -std=c11 -fms-extensions anon_struct.c -o anon_struct

+ 7 - 0
c/README.md

@ -0,0 +1,7 @@
1
# C
2
3
The ancient one, the one that's in all our systems, the one that I never
4
touch to write programs.
5
6
Still, sometimes there's a thing I'd like to try out and well, that's
7
what this place is for.

+ 30 - 0
c/anon_struct.c

@ -0,0 +1,30 @@
1
/*
2
 * Anonymous/Unnamed structs in structs (also works w/ unions).
3
 *
4
 * See https://lwn.net/SubscriberLink/548560/26d15e832d21a483/ and
5
 *  http://gcc.gnu.org/onlinedocs/gcc/Unnamed-Fields.html for details.
6
 */
7
#include <stdio.h>
8
9
// if I could do this, that would allow composition (over inheritance)
10
// in c?
11
//struct awesome {
12
//	int the_answer;
13
//};
14
15
struct composable {
16
	char *name;
17
	struct awesome {
18
		int the_answer;
19
	};
20
};
21
22
int main(void) {
23
	printf("-- anonymous structures in C11\n\n");
24
	struct composable c = {
25
		.name = "helo",
26
		.the_answer = 42
27
	};
28
	printf("composable: %s, %d\n", c.name, c.the_answer);
29
	return 0;
30
}