Welcome, Guest. Please login or register.

Author Topic: I don't think I can learn C....  (Read 10483 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: I don't think I can learn C....
« on: April 02, 2003, 11:47:17 AM »
That's cool.

Recursive call to main() :-)

I'd guess this source was generated by a program rather than created by hand, though I may be wrong :-D

-edit-

_ is a perfectly legal name. Not very useful, but legal :-D
int p; // A
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: I don't think I can learn C....
« Reply #1 on: April 02, 2003, 11:51:28 AM »
It actually looks like this thing I saw once...

A program which takes a text file and generates an encryption of it that is expressed in program flow code, execution reconstitutes the text file.

But that was in Pascal :-) Maybe somebody ported it?

As an excersise, reformat the source and see if you can disentangle it :lol:
int p; // A
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: I don't think I can learn C....
« Reply #2 on: April 02, 2003, 12:10:40 PM »
Quote

Atheist wrote:
Hello Frodon or Tickly,



Gee, hi to you too :-D Something I said? (joking)
int p; // A
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: I don't think I can learn C....
« Reply #3 on: April 02, 2003, 12:14:49 PM »
Strictly speaking it uses obsolete K&R function syntax in the declaration of main.

You should *cough* try

int main (int t, int _, char* c)
{
...
}

instead :-)
int p; // A
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: I don't think I can learn C....
« Reply #4 on: April 02, 2003, 12:18:36 PM »
You mean 14ish Kb?
int p; // A
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: I don't think I can learn C....
« Reply #5 on: April 02, 2003, 12:22:22 PM »
Quote

Atheist wrote:

I didn't say hi, because, you didn't compile it, and therefore, didn't have an answer to that question, speaking of which...



Nope, but I will tonight :-D

BTW, doesn't have to be PPC just because he used gcc. There is gcc-68K / x86 / mips etc. etc. too :-)

It's a pretty funky code example, huh?

I still think this was generated by a machine - or a serious (and frighteningly clever) geek :-)
int p; // A
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: I don't think I can learn C....
« Reply #6 on: April 02, 2003, 02:04:18 PM »
Quote

Atheist wrote:

Also, as I wondered out loud in another thread, how would going to a 64 bit CPU instruction set affect the size?

AmigaOne! "What the DLL you talkin' 'bout, fool?", Mr. T?


Here
int p; // A
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: I don't think I can learn C....
« Reply #7 on: April 02, 2003, 08:07:30 PM »
Ok everbody,

How big is the pure object file generated on your systems?

The size of the stdio / startup stuff has a lot of impact on some systems.

To see the true code generation size, just look at the unlinked object file. Should be interesting :-)
int p; // A
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: I don't think I can learn C....
« Reply #8 on: April 02, 2003, 08:54:27 PM »
Compiled under Watcom 11.0c as a Win32 character mode executable (speed rather than space opts)


02/04/2003  20:32                  881 mystery.c
02/04/2003  20:36               31,232 mystery.exe
02/04/2003  20:36              113,664 mystery.ilk
02/04/2003  20:36                   19 mystery.lk1
02/04/2003  20:36               22,729 mystery.map
02/04/2003  20:36                   89 mystery.mk
02/04/2003  20:36                  669 mystery.mk1
02/04/2003  20:36                1,496 mystery.obj
02/04/2003  20:36               16,599 mystery.sym


As you can see, the object file is only 1.4kB :-)

-edit-

Check out the winbloat! 30kb of sh*t linked just to make the exe :-D

-edit-

My guess is

1) the original text is compressed with something like LZ or dynamic huffman style compression, encoded into the big string in the middle

Quote

"@n'+,#'/*{}w+/w#cdnr/+,{}r/*de}+,/*{*+,/w{%+,/w#q#n+,/#{l,+,/n{n+\
,/+#n+,/#;#q#n+,/+k#;*+,/'r :'d*'3,}{w+K w'K:'+}e#';dq#'l q#'+d'K#!/\
+k#;q#'r}eKK#}w'r}eKK{nl]'/#;#q#n'){)#}w'){){nl]'/+#n';d}rw' i;# ){n\
l]!/n{n#'; r{#w'r nc{nl]'/#{l,+'K {rw' iK{;[{nl]'/w#q#\
n'wk nw' iwk{KK{nl]!/w{%'l##w#' i; :{nl]'/*{q#'ld;r'}{nlwb!/*de}'c \
;;{nl'-{}rw]'/+,}##'*}#nc,',#nw]'/+kd'+e}+;\
#'rdq#w! nr'/ ') }+}{rl#'{n' ')# }'+}##(!!/"


2) The binary lookup for the encoding is stored in the smaller string

Quote

"!ek;dc \
i@bK'(q)-[w]*%n+r3#l,{}:\nuwloca-O;m .vpbks,fxntdCeghiry"


3) main() is defined as a recursive extraction algorithm (similar to some huffman decoders) and character output.

4) This is an oversimplification since main() is called internally several times and tested conditionally with operator ? :...

Anybody else got any ideas?

This thing is cool :-)
int p; // A
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: I don't think I can learn C....
« Reply #9 on: April 02, 2003, 08:59:27 PM »
Quote

danamania wrote:
mine comes out to:

-rw-r--r--    1 dana     dana         2060 Apr  3 05:34 xmas.o

2060 bytes. I know little about gcc and any optimisations, but that's with 2.95 on debian woody on a 68040.

dana


Given that youre exe was only a kilibyte larger, you sure do have a good startup/stdio lib :-D
Probably just a stub that relies on OS calls deeper in?
int p; // A
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: I don't think I can learn C....
« Reply #10 on: April 02, 2003, 11:35:04 PM »
Quote

Atheist wrote:
Quote

Karlos wrote:

Check out the winbloat! 30kb of sh*t linked just to make the exe :-D



Hello Karlos,

Could you imagine 10 or 20 commands in the C: (I mean ms-dos/windos) directory, with that kind of non-sense? NOT!!!

AmigaOne! If only it were in assembler!  :-D  :-D  :-D


-edit-

You should see the sodding System32 folder!

-edit-

To be fair, the stuff in your C: directory is

1) usually written in asm (up to 3.1 anyhow)
2) Relies on AmigaOS dos.library for IO / startup

For example, the smallest hello world I got in

1) standard ANSI C : 20 kB (with stormC stdio)
2) ANSIC / dos.libnrary 500 odd bytes
3) asm / dos.library about 100 bytes

It's a real pity that exec.library RawDoFmt() doens't have proper C printf() templating - we could have a very compact stdio then.

But then again, it was written with BCPL in mind :-D
int p; // A
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: I don't think I can learn C....
« Reply #11 on: April 02, 2003, 11:56:21 PM »
Quote

My guess is

1) the original text is compressed with something like LZ or dynamic huffman style compression, encoded into the big string in the middle



Hmm, if you zip up the output it compacts down to 296 bytes (WinZip, max compression), so maybe I'm onto something...;-)
int p; // A
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: I don't think I can learn C....
« Reply #12 on: April 03, 2003, 10:10:39 AM »
Quote

Piru wrote:
68000, AmigaOS (SAS/C 6.58):
mystery                           1048 ----rwed Today    


Anybody beaten this yet?

I might see what vbcc does for ppc it tonight...
int p; // A
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: I don't think I can learn C....
« Reply #13 on: April 03, 2003, 10:36:52 AM »
Hi Crumpy,

Well, a quick summary. We went through the 'how big does the standard library bloat it out'

So we checked only the object size (not the exe). Unsurprisingly for my Win32 char mode exe attempt the stdio stuff was 20 times bigger than the actual code.

Different folks, different mileage...

Piru gave us an example of super minimalist startup code for AmigaOS and got it down to 1K :-)

I rambled about how I thought the thing worked...

You return and the thread is twice as long :-D
int p; // A
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: I don't think I can learn C....
« Reply #14 on: April 03, 2003, 11:47:09 AM »
Quote

whabang wrote:
AARGH! By all gods and somewhat  important deities! :-o :-o  :-o

I was planning to learn C or C++, but this is too much!
/me runs back home to give a big hug to FreePascal :-D


Fear not, for 'tis merely an exmple of confusication - with a capital C :-)

No real program would look like this. Unless part of the Win32 kernel :-D
int p; // A