Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Additions to C

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.

Name: Anonymous 2009-11-11 15:02

>>80
The Intel compiler is pretty good.

Name: Anonymous 2009-11-11 15:10

>>81
At haxxing anii, or at planting backdoors into your program?

Name: Anonymous 2009-11-11 15:25

>>82
Don't be silly, you can examine the code generated by most commercial compilers like Intel's C compiler or Microsoft's C compiler, just as well as you can examine the code generated by GCC.

Name: Anonymous 2009-11-11 16:40

>>82
Intel is a CPU manufacturer.
If they wanted to fuck with you, they could just "plant the backdoors" right on the chip.
Damn opensores weenies and their baseless FUD.

Name: Anonymous 2009-11-11 16:49

>>84
It's also trivial to reverse engineer compiled code, especially one that you compile yourself. Not only that, but you can have the compiler generate symbols, and assembly listings which you can examine. More likely things to happen are trojans which modify base libraries and you end up with trojaned binaries - there was a recent case of that, someone made a virus which infected Delphi system libraries.

Name: Anonymous 2009-11-11 17:13

>>85
People still use Delphi? How quaint. Yes, I'm aware people still use outdated languages, like Cobol, for more or less pragmatic reasons.

Name: Anonymous 2009-11-11 17:18

>>75
No, you see, saying "I know x86 asm pretty well" is like saying "I know C syntax pretty well", but actually worse.

Name: Anonymous 2009-11-11 17:20

>>87
You think C syntax is hard to know pretty well? Or did you mean Seppples?

Name: Anonymous 2009-11-11 17:28

>>86
Why wouldn't they? It's fucking awesome. It's like .NET, but without imposing the heinous runtime requirements on the poor souls that try to use your software.

Name: Anonymous 2009-11-11 17:32

>>89
Awesome? Granted, it's been a long time since I used Delphi, but I don't remember it being awesome.

Name: Anonymous 2009-11-11 17:34

>>89
I don't know about Delphi now, but about 2 years ago I saw a Hello World written in it that compiled to a 300 kilobyte binary.

Name: Anonymous 2009-11-11 18:15

>>91
And I thought it was retarded that an equivalent "Hello world" is 15 kb with gcc (MinGW).  (Although you can take it down to 5 kb with the -s flag.  But that's still excessive to print "hello world")

Name: Anonymous 2009-11-11 18:26

>>91
I don't use Delphi myself, but I've had some experience with it in the past. You only get such huge binaries if you statically link various libraries in with your application. If you use only what is strictly necessary, you will only get a few KB overhead. It's no different from statically linking libc costs about 60kb, statically linking MFC costs about 600KB, and dynamically linking either costs less than 1KB.
>>92
I'm not so sure about GCC, but in general it's possible to get pretty slim binaries if you dynamically link everything, strip/not include debug info(gcc tends to leave a lot of that around), use as little alignment as your executable format allows you, and optimize for less code space usage. Some further cutting down can be done by using a custom entrypoint. That should give you a tiny executable you could get without resorting to packers which compress the code and data and abuse various properties of the executable format to squeeze even more space(sometimes making illegal images, but still recognized by the OS loader).

Name: Anonymous 2009-11-11 18:31

>>93
How can I use a custom entry-point with gcc?  It would be nice to get rid of all the bullshit that gcc throws into my application by default (from msvcrt.dll I have __getmainargs, __p__environ, __p__fmode, __set_app_type, _cexit, _iob, _onexit, _setmode, abort, atexit, fflush, and signal, none of which I asked for.  And then there's SetUnhandledExceptionFilter, AddAtomA, FindAtomA, GetAtomNameA from KERNEL32.dll that I most certainly didn't ask for)

Name: Anonymous 2009-11-11 19:12

>>94
I'm not so sure about how to go about it in GCC, but in MS C compiler, you just pass /ENTRY:symbol_name to the linker(link), you can also pass /NODEFAULTLIB (to not link libc if you don't need it) and /ALIGN:# to change alignment. It should be noted though, that if you code in C and use the standard library, you will need to link against it(statically or dynamically). As for the entrypoint, you will no longer have main receive the usual parameters, instead you will probably have no params passed to you at all, in which case, you would have to obtain and parse the command line yourself if you need anything from it (along with whatever other things you may want). This all goes into platform specific code (different on windows and *nix'es), as for the exports you mention, msvcrt.dll stuff sounds like main() code, and it should go away if you set your own entrypoint, as well as the kernel32 code. SetUnhandledExceptionFilter was probably used for giving you a better error message than a simple crash of your application.

Name: Anonymous 2009-11-11 19:14

>>94
You can tag a function with __attribute__((constructor)) and gcc will cause it to be called before main(). Not sure if that's useful to you though, and afaik there's no way to order it with respect to anything else called/constructed before main().

Name: Anonymous 2009-11-11 21:13

>>95
Somewhat related reading:
http://www.catch22.net/tuts/minexe

Some of the information applies to old compilers and is a bit outdated, but the core concepts apply even though the methods have changed.

Name: Anonymous 2009-11-11 23:49

>>94
if you link explicitly instead of letting gcc do it, you gain a lot of flexibility. dump ld --help to a file and peruse it. there's lots of goodies there.

as for executable size, I don't think you can cut it down much below 2kb:

~% 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 world


naturally if you don't use puts you can cut it down because you don't need to link anything. doing the same as above (except for the -lmsvcrt of course) I ended up with a 1536 byte file. far cry from the 15kb or even 5kb that >>92 mentions, though it's certainly not 400 bytes it's not horrible either.
I know there's some way to strip off the DOS mode header from the file, I did it before, but I don't remember how. this can save some space. collapsing .idata into .text would help too, but I don't think there's any way to do that with mingw unfortunately.

Name: Anonymous 2009-11-12 0:11

>>97
You're executable will be very small
Is the grammar and/or overall quality of non-trolling 4chan posts so great that after reading 4chan for a while, stuff like this really stands out?

>>98
With MS's toolchain I can get it down to 1024 bytes:
D:\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


I then removed several hundred null bytes from the end of the file which go it to 622 bytes. If mingw lets you play with the alignment options you can probably get similar results.

Name: Anonymous 2009-11-12 1:19

>>99
You're OS is bad and you need to LURK THE FUCK MORE.

Name: Anonymous 2009-11-12 1:32

All commercial games for Sony's playstation portable are compiled with gcc.

Name: Anonymous 2009-11-12 2:10

>>99
Is the grammar and/or overall quality of non-trolling 4chan posts so great that after reading 4chan for a while, stuff like this really stands out?
That's what distinguishes the imageboard rejects from the people who remember world4ch. On /prog/, at least.

Name: Anonymous 2009-11-12 2:53

>>99
your an anus!

Name: Anonymous 2009-11-12 3:18

>>100
Hello /g/... now please return to where you belong.

Name: Anonymous 2009-11-12 11:47

>>99
I couldn't find any options for mingw to merge sections etc., although ELF ld/gcc can do it. Guess no one on the mingw team cares enough about cutting 1kb off the executable to implement that stuff.

And you can cut the file down further if you write it entirely in a hex editor. (and obviously more if you build a .com file, but that's a different subject)

Also, konata is my hostname.

Name: Anonymous 2009-11-12 13:16


HAX MYANUS

Name: Anonymous 2009-11-12 13:38

>>99
That's stood out to me since I was in grade school, so I can't really answer your question with respect to 4chan.

Anyone want some Bjarne?
http://csclub.uwaterloo.ca/media/C++0x%20-%20An%20Overview.html

Name: Anonymous 2009-11-12 15:10

Do you guys know that in Polish language the word Sepples sounds similar to "seplenić" which is the verb meaning "to lisp"?

Name: Anonymous 2009-11-12 15:21

Do you guys know that in the English language you can take the word Sepples and replace it with the sentence "hax my anus"?

Name: Anonymous 2009-11-12 15:32

>>108
Dunno lol. ヽ(´ー` )ノ

Name: Anonymous 2009-11-12 15:32

>>1 do you have any fucking idea how C compilers and likers work? for chists sake all you java niggers going on about how great namespaces are but you have no idea how this is COMPLETELY UNIMPLEMENTABLE.
IDIOTS.

Name: Anonymous 2009-11-12 15:37

>>111
I have a pretty good idea how they work and how one goes about implementing one. I don't see what the problem with implementing 'namespaces' is (you'll have to elaborate on a more exact definition of the term, but I'll assume it's either the Java/C# idea of a namespace or a module system like Scheme's, or a package system like Common Lisp's). It seems perfectly implementable to me, except that it just won't be C that you'll be implementing.

Name: Anonymous 2009-11-12 16:00

>>108
So a ``lispnik'' should really be referred to as a sepplenik.

Name: Anonymous 2009-11-12 16:39

>>112
C does not support name-mangling, all symbol names are exported as they appear in the source(with added underscore). This means you'll never see namespaces or classes or function overloading in C. If you really need those features, use C++.

Name: Anonymous 2009-11-12 16:48

>>114
It doesn't support something that could be supported, so it'll never happen.
Oh. Okay. Makes perfect sense.

Name: nullpointer 2009-11-12 16:56

...why write C when you could just write C++? If you really need to, you can write C in C++, but you also get access to a huge library and much more powerful programming concepts. I'm not trying to be a troll. I've really tried to like C. It's just that every time I read somebody else's C code, I have no fucking idea what's happening. I hacked C for a good year before I learned C++, and while I got very proficient, I just couldn't maintain my code when I came back to it later. Is there some sort of book which teaches proper C style? Even still, I see no reason to forsake C++'s extra goodness (especially with so much goodness in C++0x and/or boost.)

Somebody convert me!

Name: Anonymous 2009-11-12 17:02

>>116
It's just that every time I read somebody else's C code, I have no fucking idea what's happening
Don't blame C.  Blame the fuck-knuckles who don't understand how to write readable code in it.

Name: Anonymous 2009-11-12 17:05

>>116
Stop being 12. If you don't like C then use something else. *Please.*

Name: nullpointer 2009-11-12 17:42

>>118

That's not very helpful. I do like C. I love C. I just don't understand why restrict yourself to it alone? As I said before, I can write very readable C, and powerful C. But when I need a map data type, I know it's far more readable to use the STL than to roll my own (probably) flawed (probably) less efficient map type.

Please don't insult me, but offer a compelling exposition of your beliefs, and your reasons for holding them. Programmers tend to like logical and reasonable behaviour.

Is there an online resource, like Practical Common Lisp which teaches clean, reasonable C style and idioms?

Name: Anonymous 2009-11-12 18:09

>>119
your gay

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List