Name: Anonymous 2009-11-10 4:15
What do you want in the next C standard? For me it's namespaces, damn they make libraries simple.
int coroutine() range(int lo, int hi) {
for (int n = lo; n <= hi; n++) {
yield(n);
}
return EOF;
}
void something() {
int coroutine() gen = range(1, 10);
int value;
while ((value = gen()) != EOF)
printf("generated %d\n", value);
}something(), in my example). The compiler could insert whatever boilerplate is needed to make this work, so that the programmer no longer needs to. At the moment, I have to make structs for any coroutine I write, and pass these around. This is annoying.
~% echo 'int hi(){puts("hello world");return 0;}' > test.c
~% i486-mingw32-gcc -Os -fomit-frame-pointer -c test.c
~% i486-mingw32-ld -s -O -init=hi test.o -lmsvcrt -o test.exe
~% wc -c test.exe
2048 test.exe
~% wine test.exe
hello worldD:\Documents and Settings\konata\Desktop>cl /MD /Os /O1 test.c /link /align:4096 /filealign:512 /entry:hi /subsystem:console
t /stub:stub64.exe
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8804 for 80x86
Copyright (C) Microsoft Corp 1984-1998. All rights reserved.
test.c
Microsoft (R) Incremental Linker Version 6.00.8447
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.
/out:test.exe
/align:4096
/filealign:512
/entry:hi
/subsystem:console
/merge:.rdata=.text
/merge:.data=.text
/stub:stub64.exe
test.obj
stub64.exe : warning LNK4060: stub file missing full MS-DOS header; rebuild stub with /KNOWEAS 16-bit LINK option
LINK : warning LNK4108: /ALIGN specified without /DRIVER or /VXD; image may not run
LINK : warning LNK4078: multiple ".text" sections found with different attributes (40000040)
LINK : warning LNK4078: multiple ".text" sections found with different attributes (C0000040)
D:\Documents and Settings\konata\Desktop>wc -c test.exe
1024 test.exe
D:\Documents and Settings\konata\Desktop>test
hello world
std::map<std::basic_string<char, std::char_traits<char>, std::allocator<char> >,
std::basic_string<char, std::char_traits<char>, std::allocator<char> >,
std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> >
>, std::allocator<std::pair<std::basic_string<char, std::char_traits<char>,
std::allocator<char> > const, std::basic_string<char, std::char_traits<char>,
std::allocator<char> > > > >std::map<std::string, std::string, std::less<std::string> > is not as verbose and can even be decreased.map<string, string, std::less<string> >themacbook:~ haxus$ xxd mach-ex
0000000: cefa edfe 0700 0000 0300 0000 0200 0000 ................
0000010: 0200 0000 8800 0000 0100 0000 0100 0000 ................
0000020: 3800 0000 5f5f 5445 5854 0000 0000 0000 8...__TEXT......
0000030: 0000 0000 0000 0000 0010 0000 0000 0000 ................
0000040: c100 0000 0700 0000 0700 0000 0000 0000 ................
0000050: 0000 0000 0500 0000 5000 0000 0100 0000 ........P.......
0000060: 1000 0000 0000 0000 0c00 0000 b500 0000 ................
0000070: 0000 0000 0000 0000 0000 0000 0000 0000 ................
0000080: 0000 0000 0000 0000 0000 0000 a400 0000 ................
0000090: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000a0: 0000 0000 31d2 4053 5150 5204 03cd 8053 ....1.@SQPR....S
00000b0: 31c0 40cd 8068 656c 6c6f 2077 6f72 6c64 1.@..hello world
00000c0: 0a .
themacbook:~ haxus$ ./mach-ex
hello world