World Smallest Program

C

CK

Hi EveryBody!
This is the World Smallest Program in c.

main(l
,a,n,d)char**a;{
for(d=atoi(a[1])/10*80-
atoi(a[2])/5-596;n="@NKA\
CLCCGZAAQBEAADAFaISADJABBA^\
SNLGAQABDAXIMBAACTBATAHDBAN\
ZcEMMCCCCAAhEIJFAEAAABAfHJE\
TBdFLDAANEfDNBPHdBcBBBEA_AL\
H E L L O, W O R L D! "
[l++-3];)for(;n-->64;)
putchar(!d+++33^
l&1);}

by
CK
 
C

Chris Hills

CK said:
Hi EveryBody!
This is the World Smallest Program in c.

main(l
,a,n,d)char**a;{
for(d=atoi(a[1])/10*80-
atoi(a[2])/5-596;n="@NKA\
CLCCGZAAQBEAADAFaISADJABBA^\
SNLGAQABDAXIMBAACTBATAHDBAN\
ZcEMMCCCCAAhEIJFAEAAABAfHJE\
TBdFLDAANEfDNBPHdBcBBBEA_AL\
H E L L O, W O R L D! "
[l++-3];)for(;n-->64;)
putchar(!d+++33^
l&1);}

by
CK

int main(int var)
(
return(var +1)
)
 
S

Suman

Chris said:
CK said:
Hi EveryBody!
This is the World Smallest Program in c.

main(l
,a,n,d)char**a;{
for(d=atoi(a[1])/10*80-
atoi(a[2])/5-596;n="@NKA\
CLCCGZAAQBEAADAFaISADJABBA^\
SNLGAQABDAXIMBAACTBATAHDBAN\
ZcEMMCCCCAAhEIJFAEAAABAfHJE\
TBdFLDAANEfDNBPHdBcBBBEA_AL\
H E L L O, W O R L D! "
[l++-3];)for(;n-->64;)
putchar(!d+++33^
l&1);}

by
CK

int main(int var)
(
return(var +1)
)
....and this compiles on? Not with my gcc 4.0.0 though!
BTW: what's wrong with int main(){} ?
 
R

Richard Bos

[ Snip ten more lines ]
int main(int var)
(
return(var +1)
)

Well, it's just as much the smallest, and just as much a C program.

The answer, perhaps surprisingly (or perhaps not) is different for C89
and for C99. Guess which is smaller?

Richard
 
S

Suman

Richard said:
[ Snip ten more lines ]
int main(int var)
(
return(var +1)
)

Well, it's just as much the smallest, and just as much a C program.

The answer, perhaps surprisingly (or perhaps not) is different for C89
and for C99. Guess which is smaller?
Guess what, I was going to append the gcc call that I used
(blame it on hubris or what you will):
gcc -std=c99 -Wall -pedantic -ansi test.c

AFAIR, there's no falling-off of main in C89. Is that what you mean?
 
R

Rob Morris

???? In what sense, it is worlds smallest? and what does it do?

-santosh
It's not the world's smallest, it's the "World Smallest"

Call it with 2 or more arguments, and it prints out a little text world
map, though I'm not sure how portable it is. I'm sure we've all written
little text-picture-encoded-in-a-string programs, but I found it a
fairly amusing post.
 
R

Richard Bos

Rob Morris said:
It's not the world's smallest, it's the "World Smallest"

Call it with 2 or more arguments, and it prints out a little text world
map, though I'm not sure how portable it is. I'm sure we've all written
little text-picture-encoded-in-a-string programs, but I found it a
fairly amusing post.

But it still isn't the smallest, nor print the smallest. This does:

#include <stdio.h>
int main(void){puts(".");}

C99, of course. And it's a _very_ small world map.

Richard
 
D

Dave Vandervies

[ Snip ten more lines ]
int main(int var)
(
return(var +1)
)

Well, it's just as much the smallest, and just as much a C program.

If you print the first one in flyspeck-3 and the second one in a
readable font, you might be able to miss little details like that for
the first one.

The answer, perhaps surprisingly (or perhaps not) is different for C89
and for C99. Guess which is smaller?

That would be "It depends", if I'm not mistaken. Do we have to have a
sensible return value?

In no specified order:
--------
main(){}
--------
int main(){}
--------
main(){return 0;}
--------
Depending on implementation-defined (or is it unspecified?) aspects of
the implementation used to implement the implementation you're using
(if I'm not mistaken and haven't confused myself putting that clause
together), you may or may not be able to get away with dropping the
newline after the `}'.


dave
(now how 'bout "smallest doing something useful"?)
 
A

Anonymous 7843

Hi EveryBody!
This is the World Smallest Program in c.

main(l
,a,n,d)char**a;{
for(d=atoi(a[1])/10*80-
atoi(a[2])/5-596;n="@NKA\
CLCCGZAAQBEAADAFaISADJABBA^\
SNLGAQABDAXIMBAACTBATAHDBAN\
ZcEMMCCCCAAhEIJFAEAAABAfHJE\
TBdFLDAANEfDNBPHdBcBBBEA_AL\
H E L L O, W O R L D! "
[l++-3];)for(;n-->64;)
putchar(!d+++33^
l&1);}

I'm guessing that it's not original. Possibly it was
originally an IOCCC entry and formatted like so:

main(l
,a,n,d)char**a;{
for(d=atoi(a[1])/10*80-
atoi(a[2])/5-596;n="@NKA\
CLCCGZAAQBEAADAFaISADJABBA^\
SNLGAQABDAXIMBAACTBATAHDBAN\
ZcEMMCCCCAAhEIJFAEAAABAfHJE\
TBdFLDAANEfDNBPHdBcBBBEA_AL\
H E L L O, W O R L D! "
[l++-3];)for(;n-->64;)
putchar(!d+++33^
l&1);}

[fixed-width font required]

Such that the program itself resembles the world. I suspect
that the original author would not have been so quick to
remove the indentation.

http://www.ioccc.org/1992/westley.c
 
R

Richard Bos

That would be "It depends", if I'm not mistaken. Do we have to have a
sensible return value?

Well, yes, of course. Otherwise, we could just leave it empty and claim
that "Link: no such function as main()" is the output of our program.
(now how 'bout "smallest doing something useful"?)

Ah, now there's a mare's nest. How does one define "useful"? Always
returning zero could be useful in some circumstances, for example as a
stub in makefiles.

Richard
 
C

Chris Croughton

Well, yes, of course. Otherwise, we could just leave it empty and claim
that "Link: no such function as main()" is the output of our program.


Ah, now there's a mare's nest. How does one define "useful"? Always
returning zero could be useful in some circumstances, for example as a
stub in makefiles.

true.c:

int main(void) {return 0;}

Very useful in Unix-like shells. For 'false' to be portable requires a
header, unfortunately (although Unix-like systems usually say that it
returns 1 explicitly, because the implementation defines how the values
returned are treated by the system).

Chris C
 
K

Keith Thompson

Chris Croughton said:
true.c:

int main(void) {return 0;}

Very useful in Unix-like shells. For 'false' to be portable requires a
header, unfortunately (although Unix-like systems usually say that it
returns 1 explicitly, because the implementation defines how the values
returned are treated by the system).

<SOMEWHAT_OT>
I've seen implementations of /bin/false that return a value of 255.
(Unix treats any non-zero status as false.)

If it's for Unix only, portability isn't much of a concert; "exit 1;"
is ok.
</SOMEWHAT_OT>
 
D

Dave Vandervies

Keith Thompson said:
<SOMEWHAT_OT>
If it's for Unix only, portability isn't much of a concert; "exit 1;"
is ok.

I would think that "return 1;" or "exit(1);" would be better, at least
if you're planning to put it in something you're giving to a C compiler.
</SOMEWHAT_OT>


dave
(regularly uses a system where /bin/false is "exit 1")
 
K

Keith Thompson

I would think that "return 1;" or "exit(1);" would be better, at least
if you're planning to put it in something you're giving to a C compiler.



dave
(regularly uses a system where /bin/false is "exit 1")

Sorry, I forgot to add the

#define exit exit(1);

above the "exit 1;".

(Either than, or I had just been looking at a /bin/false
implementation that happened to be a Bourne shell script, and I simply
wasn't paying enough attention to what I was writing -- but that
hardly seems plausible.)
 
K

kurtdriver

Richard said:
But it still isn't the smallest, nor print the smallest. This does:

#include <stdio.h>
int main(void){puts(".");}

C99, of course. And it's a _very_ small world map.

Richard

cc version 4.0.0 compiled this and not only is it a tad smaller, but
it displays the world's smallest solar system!
#include <stdio.h>
int main(){puts(".");}
 
K

Keith Thompson

cc version 4.0.0 compiled this and not only is it a tad smaller, but
it displays the world's smallest solar system!
#include <stdio.h>
int main(){puts(".");}

The universe before the big bang. Actual size.
 
D

Dik T. Winter

> I've seen implementations of /bin/false that return a value of 255.
> (Unix treats any non-zero status as false.)

They are mostly shell-scripts. The Solaris script I am looking at returns
255, and is at version 1.6. I remember a Cray script returning the same
value and being at version 32.1 or something like that. But on the Linux
system I am using it is 1 (but it is not a script, but a compiled program,
and it refused to give the version).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top