Welcome, Guest. Please login or register.

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

Description:

0 Members and 1 Guest are viewing this topic.

Offline AtheistTopic starter

  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 820
    • Show only replies by Atheist
I don't think I can learn C....
« on: April 02, 2003, 11:07:15 AM »
Found this source code example on the net...

/*
As an extreme example the following C code (mystery.c) is actually legal C code.


#include

main(t,_,a)
char *a;
{return!0main(-86, 0, a+1 )+a)):1,t<_?main(t+1, _, a ):3,main ( -94, -27+t, a
)&&t == 2 ?_<13 ?main ( 2, _+1, "%s %d %d\n" ):9:16:t<0?t<-72?main(_,
t,"@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' ')# }'+}##(!!/")
:t<-50?_==*a ?putchar(a[31]):main(-65,_,a+1):main((*a == '/')+t,_,a\
+1 ):0i@bK'(q)-[w]*%n+r3#l,{}:\nuwloca-O;m .vpbks,fxntdCeghiry"),a+1);}
*/

AmigaOne! Dumbfounded!!
\\"Which would you buy? The Crappy A1200, 15 years out of date... or the Mobile Phone that I have?\\" -- bloodline
So I guess that A500, 600, 1000, 2000, CDTV, CD32, are pure garbage then? Thanks for posting here.
 

Offline xeron

  • Hero Member
  • *****
  • Join Date: Mar 2002
  • Posts: 2533
    • Show only replies by xeron
    • http://www.petergordon.org.uk
Re: I don't think I can learn C....
« Reply #1 on: April 02, 2003, 11:13:24 AM »
Ahh yes. Reminds me of the obfuscated C competitions. I've seen some C sources like that that were shaped like a train or a whale, which is fun.

Nice example there; interesting use of recursion and the ? operator. I also didn't realise '_' was a legal variable name.

Of course, some languages like Brainf**k, Perl and my own "Bonk" are pretty obfuscated as a matter of course  :-D
Playstation Network ID: xeron6
 

Offline Frodon

  • Full Member
  • ***
  • Join Date: Jan 2003
  • Posts: 127
    • Show only replies by Frodon
    • http://www.asum.asso.fr/
Re: I don't think I can learn C....
« Reply #2 on: April 02, 2003, 11:14:59 AM »
On the first day of Christmas my true love gave to me
a partridge in a pear tree.

On the second day of Christmas my true love gave to me
two turtle dovesin a pear tree.

On the third day of Christmas my true love gave to me
three french hens, two turtle doves

On the fourth day of Christmas my true love gave to me
four calling birds, three french hens, two turtle doves

On the fifth day of Christmas my true love gave to me
five gold rings;ds, three french hens, two turtle doves
and a partridge in a pear tree.

On the sixth day of Christmas my true love gave to mees
and a partridge in a pear tree.

On the eighth day of Christmas my true love gave to me
eight maids a-milking, seven swans a-swimming,
six geese a-laying, five gold rings;
four calling birds, three french hens, two turtle doves
and a partridge in a pear tree.

On the ninth day of Christmas my true love gave to me
nine ladies dancing, eight maids a-milking, seven swans a-swimming,
six geese a-laying, five gold rings;
four calling birds, three french hens, two turtle doves
and a partridge in a pear tree.

On the tenth day of Christmas my true love gave to me
ten lords a-leaping,
and a partridge in a pear tree.

ten lords a-leaping,Christmas my true love gave to me
nine ladies dancing, eight maids a-milking, seven swans a-swimming,
six geese a-laying, five gold rings;
four calling birds, three french hens, two turtle doves
and a partridge in a pear tree.

eleven pipers piping, ten lords a-leaping,ove gave to me
nine ladies dancing, eight maids a-milking, seven swans a-swimming,
six geese a-laying, five gold rings;
four calling birds, three french hens, two turtle doves
and a partridge in a pear tree.

twelve drummers drumming, eleven pipers piping, ten lords a-leaping,
nine ladies dancing, eight maids a-milking, seven swans a-swimming,
six geese a-laying, five gold rings;
four calling birds, three french hens, two turtle doves
and a partridge in a pear tree.
Frodo Baggins

Fleecy Moss, Aug 1999: \\"You may have bought the name Amiga, but the community is something you have to earn. AInc have never understood that, and now there is another company\\"
 

Offline xeron

  • Hero Member
  • *****
  • Join Date: Mar 2002
  • Posts: 2533
    • Show only replies by xeron
    • http://www.petergordon.org.uk
Re: I don't think I can learn C....
« Reply #3 on: April 02, 2003, 11:19:28 AM »
Is that what it does? thats really cool  :-D

Edit: Just compiled it, and yes it does. Thats very clever, i'm impressed!
Playstation Network ID: xeron6
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show only replies by Karlos
Re: I don't think I can learn C....
« Reply #4 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 only replies by Karlos
Re: I don't think I can learn C....
« Reply #5 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 AtheistTopic starter

  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 820
    • Show only replies by Atheist
Re: I don't think I can learn C....
« Reply #6 on: April 02, 2003, 12:06:25 PM »
Hello Frodon or Tickly,

I was wondering, how many bytes is the compiled code?

AmigaOne! Dumbfounded + Amazed!


P.S. Found it here http://www.cs.cf.ac.uk/Dave/C/node4.html#SECTION00460000000000000000
\\"Which would you buy? The Crappy A1200, 15 years out of date... or the Mobile Phone that I have?\\" -- bloodline
So I guess that A500, 600, 1000, 2000, CDTV, CD32, are pure garbage then? Thanks for posting here.
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show only replies by Karlos
Re: I don't think I can learn C....
« Reply #7 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 Crumpster

  • Full Member
  • ***
  • Join Date: Mar 2002
  • Posts: 215
  • Country: gb
    • Show only replies by Crumpster
Re: I don't think I can learn C....
« Reply #8 on: April 02, 2003, 12:12:23 PM »
That's Cool,

I compiled it in gcc no probs, (well had to uncomment it 1st)
Now all I have to do is figure out how it does it.

Stay tuned folks I'm sure I'll figure it out by this time next year!!  :-D

Cheers,

Crumpster
A1-XE - G4 800MHz, 1GB RAM, 80GB HDD, Radeon 9250, OS 4.1
A1200T - PPC603 240MHz / 68040 50MHz, 128MB RAM, Mediator, OS 3.9 / 4.1
A1200 (No. 2) - M-TEC 68030 50MHz, 4GB CF, KS 3.0, OS 3.0
A500 - ACA500 with ACA1232.
CDTV - in Progress: SCSI, 9 pin joy/mouse connectors, KS switcher.

Non-CBM - Atari STe, Atari Falcon, Apple ][e, ZX Spectrum, CPC6128.
Gone but not forgotten (and slowly getting them back): CPC464, C64, Vic-20.

I may have a problem
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show only replies by Karlos
Re: I don't think I can learn C....
« Reply #9 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 Crumpster

  • Full Member
  • ***
  • Join Date: Mar 2002
  • Posts: 215
  • Country: gb
    • Show only replies by Crumpster
Re: I don't think I can learn C....
« Reply #10 on: April 02, 2003, 12:17:53 PM »
@ Athiest

Compiled size here (RedHat 7.3 / gcc 2.96) is 14540 bytes or 14ish Kb.

Cheers,

Crumpster


Changed the Kb size to 14 - cheers Karlos
A1-XE - G4 800MHz, 1GB RAM, 80GB HDD, Radeon 9250, OS 4.1
A1200T - PPC603 240MHz / 68040 50MHz, 128MB RAM, Mediator, OS 3.9 / 4.1
A1200 (No. 2) - M-TEC 68030 50MHz, 4GB CF, KS 3.0, OS 3.0
A500 - ACA500 with ACA1232.
CDTV - in Progress: SCSI, 9 pin joy/mouse connectors, KS switcher.

Non-CBM - Atari STe, Atari Falcon, Apple ][e, ZX Spectrum, CPC6128.
Gone but not forgotten (and slowly getting them back): CPC464, C64, Vic-20.

I may have a problem
 

Offline Karlos

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

Offline AtheistTopic starter

  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 820
    • Show only replies by Atheist
Re: I don't think I can learn C....
« Reply #12 on: April 02, 2003, 12:18:41 PM »
Quote

Karlos wrote:
Quote

Atheist wrote:
Hello Frodon or Tickly,



Gee, hi to you too :-D Something I said? (joking)


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

Hello Crumpster,

gcc, so that would be PPC and therefore RISC, so how many bytes was it, when you compiled it?

Thanks, I just HAD to know.


AmigaOne! C(++), ...phew!! Challenging!
\\"Which would you buy? The Crappy A1200, 15 years out of date... or the Mobile Phone that I have?\\" -- bloodline
So I guess that A500, 600, 1000, 2000, CDTV, CD32, are pure garbage then? Thanks for posting here.
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show only replies by Karlos
Re: I don't think I can learn C....
« Reply #13 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 Crumpster

  • Full Member
  • ***
  • Join Date: Mar 2002
  • Posts: 215
  • Country: gb
    • Show only replies by Crumpster
Re: I don't think I can learn C....
« Reply #14 on: April 02, 2003, 12:24:52 PM »
@ Karlos

yep 14 ish Kb sorry finger slipped on the decimal point
(I obviously can't count, did I cover it ok?  :-P )

Thanks fo the correction.

@ Athiest

Not on an A1 yet I'm afraid, crappy works P2 233Mhz with redhat 7.3 on it.

Cheers

Crumpy
A1-XE - G4 800MHz, 1GB RAM, 80GB HDD, Radeon 9250, OS 4.1
A1200T - PPC603 240MHz / 68040 50MHz, 128MB RAM, Mediator, OS 3.9 / 4.1
A1200 (No. 2) - M-TEC 68030 50MHz, 4GB CF, KS 3.0, OS 3.0
A500 - ACA500 with ACA1232.
CDTV - in Progress: SCSI, 9 pin joy/mouse connectors, KS switcher.

Non-CBM - Atari STe, Atari Falcon, Apple ][e, ZX Spectrum, CPC6128.
Gone but not forgotten (and slowly getting them back): CPC464, C64, Vic-20.

I may have a problem