program

M

Morris Dovey

Richard said:
.... just because I like to have the compiler *find* the headers I include.
:)

Yes yes - mine tells me when it can't find 'em and that usually
provides the converstational opening for extended discussions
with myself...

'S what happens when I try to do too many things at the same time
or when my brain runs off leaving my (fumble) fingers all alone.

Every once in a great while I really do get it right on the first
try. (-:
 
O

Old Wolf

I think the smallest working program (of this kind) would be, assuming
Sean's assumptions, something like this:

#include <stdio.h>
int
n[257]={-1,0};main(){while(++n[getchar()+1]);printf("%d,%d,%d\n",n[98]+

n[257]={-1};

My compiler (gcc 3.3.1) allows the "int" to be omitted (it gives a
warning).
Is this standard?

How about this one:

_

(1 char). NOTE: compile with gcc -D_='int
n[257]={-1};main(){while(++n[getchar()+1]);printf("%d,%d,%d\n",n[98]+n[66],n[99]+n[67],n[100]+n[68]);}'
 
D

Dave Thompson

On 19 Jan 2004 10:50:48 GMT, Joona I Palaste <[email protected]>
wrote:
I have two more entries. Both consist of only one function.

First version (191 characters), one local variable declaration, one
statement.

#include <stdio.h>
#include <ctype.h>
int a[4]={0};int main(void){int c=tolower(getchar());return c==EOF?(printf(
"%d %d %d\n",a[0],a[1],a[2]),0):(a[c=='a'?0:c=='b'?1:c=='c'?2:3]++,main());}
As noted elsethread you don't need the initializer ={0} for static
vars, including as here file-scope; and don't need int on main() for
C89 while you don't need to return a value in C99 although the value
you use is nonstandard anyway, the elsethread version was !printf....
Second version (200 characters), no local variables, one statement. But
I'm not sure if this is completely ISO compliant because it modifies
main()'s first parameter.
That is perfectly legal; you can change argc, argv (where it points),
and the strings (char arrays, within their initial length only)
pointed to by the (non-null, i.e. i < argc) elements of argv. The
one thing not guaranteed modifiable by the standard is the *pointers*
argv, although in practice I can't imagine any reasonable
implementation where they aren't actually modifiable.

But why would you want to, in this case; it makes the program both
longer and more obfuscated ... oh, I see; objection withdrawn.

- David.Thompson1 at worldnet.att.net
 

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

Forum statistics

Threads
473,781
Messages
2,569,615
Members
45,297
Latest member
EngineerD

Latest Threads

Top