By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,952 Members | 1,416 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,952 IT Pros & Developers. It's quick & easy.

C ONE LINER

P: n/a
Can you determine output of following one liner by visual inspection..
It had won an award in obfuscated C contest.....
main() { printf(&unix["\021%six\012\0"],(unix)["have"]+"fun"-060);}
You can also list your favourite one liner...
Nov 18 '08 #1
Share this Question
Share on Google+
37 Replies


P: n/a
On Nov 18, 11:29*am, "c.lang.mys...@gmail.com"
<c.lang.mys...@gmail.comwrote:
Can you determine output of following one liner by visual inspection..
It had won an award in obfuscated C contest.....

main() { printf(&unix["\021%six\012\0"],(unix)["have"]+"fun"-060);}

You can also list your favourite one liner...
So what is your C related question? Your posts are getting more and
more nauseous.

Nov 18 '08 #2

P: n/a
On 18 Nov, 11:29, "c.lang.mys...@gmail.com" <c.lang.mys...@gmail.com>
wrote:
Can you determine output of following one liner by visual inspection..
It had won an award in obfuscated C contest.....

main() { printf(&unix["\021%six\012\0"],(unix)["have"]+"fun"-060);}
Is "unix" supposed to be defined and, if so, as what?
Nov 18 '08 #3

P: n/a
On Tue, 18 Nov 2008 15:12:42 -0800 (PST),
gw****@aol.com <gw****@aol.comwrote:
On 18 Nov, 11:29, "c.lang.mys...@gmail.com" <c.lang.mys...@gmail.com>
wrote:
>Can you determine output of following one liner by visual inspection..
It had won an award in obfuscated C contest.....

main() { printf(&unix["\021%six\012\0"],(unix)["have"]+"fun"-0×60);}

Is "unix" supposed to be defined and, if so, as what?
It's the 1987 IOCCC entry by David Korn. Look it up with Google.

Martien
--
|
Martien Verbruggen | Quick! Hire a teenager while they still know
| everything.
|
Nov 19 '08 #4

P: n/a
gw****@aol.com wrote:
"c.lang.mys...@gmail.com" <c.lang.mys...@gmail.comwrote:
>Can you determine output of following one liner by visual
inspection. It had won an award in obfuscated C contest.

main() {printf(&unix["\021%six\012\0"],(unix)["have"]+"fun"-060);}

Is "unix" supposed to be defined and, if so, as what?
He says it is a one liner, so there is no way for it to be defined.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
Nov 19 '08 #5

P: n/a
CBFalconer wrote:
gw****@aol.com wrote:
>"c.lang.mys...@gmail.com" <c.lang.mys...@gmail.comwrote:
>>Can you determine output of following one liner by visual
inspection. It had won an award in obfuscated C contest.

main() {printf(&unix["\021%six\012\0"],(unix)["have"]+"fun"-060);}
Is "unix" supposed to be defined and, if so, as what?

He says it is a one liner, so there is no way for it to be defined.
Giving the compiler the command line option "-Dunix=1" would make that
code work as expected on most of the C89 compilers I've ever used.

There were compilers that pre-defined 'unix' automatically. Such
compilers do not conform to any version of the C standard, but that
doesn't make them non-existent. It does make code which relies on their
non-conforming features off-topic.

Nov 19 '08 #6

P: n/a
James Kuyper wrote:
CBFalconer wrote:
>gw****@aol.com wrote:
>>"c.lang.mys...@gmail.com" <c.lang.mys...@gmail.comwrote:

Can you determine output of following one liner by visual
inspection. It had won an award in obfuscated C contest.

main() {printf(&unix["\021%six\012\0"],(unix)["have"]+"fun"-060);}
Is "unix" supposed to be defined and, if so, as what?

He says it is a one liner, so there is no way for it to be defined.

Giving the compiler the command line option "-Dunix=1" would make that
code work as expected on most of the C89 compilers I've ever used.
Didn't think of that :-)

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
Nov 19 '08 #7

P: n/a
gw****@aol.com writes:
On 18 Nov, 11:29, "c.lang.mys...@gmail.com" <c.lang.mys...@gmail.com>
wrote:
>Can you determine output of following one liner by visual inspection..
It had won an award in obfuscated C contest.....

main() { printf(&unix["\021%six\012\0"],(unix)["have"]+"fun"-060);}

Is "unix" supposed to be defined and, if so, as what?
Many years ago, Unix C compilers typically predefined the macro
"unix", so programmers could write:

#ifdef unix
/* Unix-specific code */
#endif

Modern C compilers aren't allowed to do that, since "unix" is in the
programmer's namespace, but the early compilers didn't make any such
guarantees.

The above code, (with "0?60" replaced by "0x60") is from the 1987
International Obfuscated C Code Contest (IOCCC); it was submitted by
David Korn, author of the Korn shell. If you want spoilers, go to
<http://www.ioccc.org/>.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Nov 19 '08 #8

P: n/a
Keith Thompson wrote:
gw****@aol.com writes:
>On 18 Nov, 11:29, "c.lang.mys...@gmail.com" <c.lang.mys...@gmail.com>
....
>>main() { printf(&unix["\021%six\012\0"],(unix)["have"]+"fun"-060);}
....
The above code, (with "0?60" replaced by "0x60") is from the 1987
For all messages I've seen on this thread, that text displays as 0x60,
not 0?60, both from my Thunderbird newsreader and when using Firefox to
view the messages on Google Groups.
Nov 19 '08 #9

P: n/a
"James Kuyper" <ja*********@verizon.netwrote in message
news:Bh*****************@nwrddc02.gnilink.net...
Keith Thompson wrote:
>gw****@aol.com writes:
>>On 18 Nov, 11:29, "c.lang.mys...@gmail.com" <c.lang.mys...@gmail.com>
...
>>>main() { printf(&unix["\021%six\012\0"],(unix)["have"]+"fun"-060);}
...
>The above code, (with "0?60" replaced by "0x60") is from the 1987

For all messages I've seen on this thread, that text displays as 0x60, not
0?60, both from my Thunderbird newsreader and when using Firefox to view
the messages on Google Groups.
Mine is displaying it as the "times" symbol rather than the letter "x".
That is, it's not the same character as the "x" in "unix" at the start of
the line. If I save it and do a binary dump on it, it comes up as code 0xD7
rather than the 0x78 of a lower case "x". I assume Keith's news reader
substitutes "?" when the character code is outside the standard ASCII set.

- Bill

Nov 19 '08 #10

P: n/a
Bill Leary wrote:
"James Kuyper" <ja*********@verizon.netwrote in message
news:Bh*****************@nwrddc02.gnilink.net...
>Keith Thompson wrote:
>>gw****@aol.com writes:
On 18 Nov, 11:29, "c.lang.mys...@gmail.com" <c.lang.mys...@gmail.com>
...
>>>>main() { printf(&unix["\021%six\012\0"],(unix)["have"]+"fun"-060);}
...
>>The above code, (with "0?60" replaced by "0x60") is from the 1987

For all messages I've seen on this thread, that text displays as 0x60,
not 0?60, both from my Thunderbird newsreader and when using Firefox
to view the messages on Google Groups.

Mine is displaying it as the "times" symbol rather than the letter "x".
You're right, I missed that distinction - I can see the difference, now
that I know what to look for. I've just checked, and it displays as the
"times" symbol in all messages in this thread.
Nov 19 '08 #11

P: n/a
In article <Bh*****************@nwrddc02.gnilink.net>,
James Kuyper <ja*********@verizon.netwrote:
>For all messages I've seen on this thread, that text displays as 0x60,
not 0?60, both from my Thunderbird newsreader and when using Firefox to
view the messages on Google Groups.
It's a Latin-1 multiplication symbol, which looks very like a letter-x.

-- Richard
--
Please remember to mention me / in tapes you leave behind.
Nov 19 '08 #12

P: n/a
James Kuyper wrote:
Keith Thompson wrote:
>gw****@aol.com writes:
>>On 18 Nov, 11:29, "c.lang.mys...@gmail.com" <c.lang.mys...@gmail.com>
....
>>>main() { printf(&unix["\021%six\012\0"],(unix)["have"]+"fun"-0×60);}
....
>The above code, (with "0?60" replaced by "0x60") is from the 1987

For all messages I've seen on this thread, that text displays as 0x60,
not 0?60, both from my Thunderbird newsreader and when using Firefox to
view the messages on Google Groups.
No, it doesn't. Firefox properly renders the non-ascii character in
"0×60" as '×', not 'x'.
Nov 19 '08 #13

P: n/a
Martin Ambuhl <ma*****@earthlink.netwrites:
James Kuyper wrote:
>Keith Thompson wrote:
>>gw****@aol.com writes:
On 18 Nov, 11:29, "c.lang.mys...@gmail.com" <c.lang.mys...@gmail.com>
....
>>>>main() { printf(&unix["\021%six\012\0"],(unix)["have"]+"fun"-060);}
....
>>The above code, (with "0?60" replaced by "0x60") is from the 1987
For all messages I've seen on this thread, that text displays as
0x60, not 0?60, both from my Thunderbird newsreader and when using
Firefox to view the messages on Google Groups.

No, it doesn't. Firefox properly renders the non-ascii character in
"060" as '', not 'x'.
It probably depends on how Firefox and the underlying OS are
configured, and what assumptions Firefox makes about the web page it's
trying to render.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Nov 19 '08 #14

P: n/a
>main() { printf(&unix["\021%six\012\0"],(unix)["have"]+"fun"-060);}

Nowadays, it'd have to be a two-liner: the Standard (5.1.1.2 P 1, section
2) "A source file that is not empty shall end in a new-line character..."
--
#include <standard.disclaimer>
_
Kevin D Quitt USA 91387-4454 96.37% of all statistics are made up
Nov 19 '08 #15

P: n/a
Kevin D. Quitt <KQ****@IEEInc.comwrites:
>>main() { printf(&unix["\021%six\012\0"],(unix)["have"]+"fun"-060);}
Nowadays, it'd have to be a two-liner: the Standard (5.1.1.2 P 1, section
2) "A source file that is not empty shall end in a new-line character..."
How does that make it a two-liner?

You'd have to add a declaration for printf and make some other small
tweaks, but as long as you can persuade the compiler to predefine the
"unix" macro it should be doable in one line.

Here's my attempt. With all unnecessary whitespace deleted, it's 117
characters long, not counting the new-line.

int printf(const char*restrict format,...);int main(void){printf(&unix["\021%six\012\0"],(unix)["have"]+"fun"-0x60);}

Or if you have problems with long lines:

int printf(const char*restrict format,...);
int main(void){printf(&unix["\021%six\012\0"],(unix)["have"]+"fun"-0x60);}

Note that I'm assuming C99, so printf needs the "restrict" keyword and
the "return 0;" is implicit.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Nov 19 '08 #16

P: n/a
Keith Thompson <ks***@mib.orgwrites:
[...]
As recently as gcc 4.3.2 on Ubuntu, "unix" *is* predefined as a macro
with the value 1. I've never heard of ti being an implicitly declared
automatic variable.
[...]

Sorry, I meant to mention that "-ansi" turns this off. (And as long
as I'm correcting myself, "ti" should be "it".)

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Nov 19 '08 #17

P: n/a
Keith Thompson wrote:
Keith Thompson <ks***@mib.orgwrites:
[...]
>As recently as gcc 4.3.2 on Ubuntu, "unix" *is* predefined as
a macro with the value 1. I've never heard of ti being an
implicitly declared automatic variable.
[...]

Sorry, I meant to mention that "-ansi" turns this off. (And
as long as I'm correcting myself, "ti" should be "it".)
I imagine "-std=c99" will also shut it off.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
Nov 20 '08 #18

P: n/a

<c.***********@gmail.comwrote in message
news:0f**********************************@w1g2000p rk.googlegroups.com...
Can you determine output of following one liner by visual inspection..
It had won an award in obfuscated C contest.....
main() { printf(&unix["\021%six\012\0"],(unix)["have"]+"fun"-060);}
You can also list your favourite one liner...

Where is:

#include <stdio.h>

?

Nov 20 '08 #19

P: n/a
"Chris M. Thomasson" <no@spam.invalidwrote in message
news:ql***************@newsfe22.iad...
>
<c.***********@gmail.comwrote in message
news:0f**********************************@w1g2000p rk.googlegroups.com...
>Can you determine output of following one liner by visual inspection..
It had won an award in obfuscated C contest.....

>main() { printf(&unix["\021%six\012\0"],(unix)["have"]+"fun"-060);}

>You can also list your favourite one liner...


Where is:

#include <stdio.h>

?
Implicit.

Nov 20 '08 #20

P: n/a
Chris M. Thomasson said:
"Chris M. Thomasson" <no@spam.invalidwrote in message
news:ql***************@newsfe22.iad...
>>
<c.***********@gmail.comwrote in message
news:0f**********************************@w1g2000 prk.googlegroups.com...
>>Can you determine output of following one liner by visual inspection..
It had won an award in obfuscated C contest.....

>>main() { printf(&unix["\021%six\012\0"],(unix)["have"]+"fun"-060);}

>>You can also list your favourite one liner...


Where is:

#include <stdio.h>

?

Implicit.

No, you were right the first time. It's missing. The behaviour of the
program is consequently undefined (calling a variadic function without a
valid function prototype in scope). A certain degree of latitude is often
granted to IOCCC programs that would not be acceptable in a production
environment. IOCCC is, after all, supposed to be a refuge for abused C
code, n'est ce pas?

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Nov 20 '08 #21

P: n/a
Andrey Tarasevich <an**************@hotmail.comwrites:
BTW, why did the original author put a pair of braces around 'unix' in
(unix)["have"]+"fun"-0x60'?
I assume it was to make it look like a cast.

(Language barrier: to me, these characters ( ) are parentheses. Braces
are these { } . These [ ] are brackets.)

Nov 20 '08 #22

P: n/a
Richard Heathfield <rj*@see.sig.invalidwrites:
Chris M. Thomasson said:
>"Chris M. Thomasson" <no@spam.invalidwrote in message
news:ql***************@newsfe22.iad...
>>>
<c.***********@gmail.comwrote in message
news:0f**********************************@w1g200 0prk.googlegroups.com...
Can you determine output of following one liner by visual inspection..
It had won an award in obfuscated C contest.....
main() { printf(&unix["\021%six\012\0"],(unix)["have"]+"fun"-060);}
You can also list your favourite one liner...
Where is:

#include <stdio.h>

?

Implicit.


No, you were right the first time. It's missing. The behaviour of the
program is consequently undefined (calling a variadic function without a
valid function prototype in scope). A certain degree of latitude is often
granted to IOCCC programs that would not be acceptable in a production
environment. IOCCC is, after all, supposed to be a refuge for abused C
code, n'est ce pas?
Further allowances should be made for the fact that the code in question
is from 1987, pre-C90, and the rules only asked for the code to conform
to K&R ("plus common extensions"). Under K&R C, the use of printf would
create the implicit declaration `extern int printf();' which would
suffice.

So the inclusion of stdio.h is not implicit, but the only relevant
declaration that it contains, is.
Nov 20 '08 #23

P: n/a
c.***********@gmail.com wrote:
Can you determine output of following one liner by visual inspection..
It had won an award in obfuscated C contest.....
main() { printf(&unix["\021%six\012\0"],(unix)["have"]+"fun"-0�60);}
You can also list your favourite one liner...
There is no #include<stdio.h>
It will generate a compilation error saying printf is not defined.
Nov 20 '08 #24

P: n/a
Nate Eldredge wrote:
Andrey Tarasevich <an**************@hotmail.comwrites:
>BTW, why did the original author put a pair of braces around 'unix' in
(unix)["have"]+"fun"-0x60'?

I assume it was to make it look like a cast.

(Language barrier: to me, these characters ( ) are parentheses. Braces
are these { } . These [ ] are brackets.)
To you?

Here, have an authoritative source:

ISO/IEC 9899:1999 (E)

( )(parentheses punctuator), 6.7.5.3, 6.8.4, 6.8.5

[ ](brackets punctuator), 6.7.5.2, 6.7.8

{ }(braces punctuator), 6.7.2.2, 6.7.2.3, 6.7.8, 6.8.2

--
pete
Nov 20 '08 #25

P: n/a
In article <oc******************************@bt.comrj*@see.sig.invalid writes:
....
No, you were right the first time. It's missing. The behaviour of the
program is consequently undefined (calling a variadic function without a
valid function prototype in scope).
That entry is from the IOCCC of 1987. At that time there was no such
requirement.
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
Nov 20 '08 #26

P: n/a
Michael said:
c.***********@gmail.com wrote:
>Can you determine output of following one liner by visual inspection..
It had won an award in obfuscated C contest.....
main() { printf(&unix["\021%six\012\0"],(unix)["have"]+"fun"-0?60);}
You can also list your favourite one liner...
There is no #include<stdio.h>
It will generate a compilation error saying printf is not defined.
The lack of a definition for printf isn't a problem for a compiler - the
definition could easily be (and, in this case, is) in some other object
file or library. If the *linker* can't find it, that's another matter.

The lack of a *declaration* is a problem for ISO C - the behaviour is
undefined under ISO C rules. But since the program was written before C
was standardised, I don't suppose the author will be losing any sleep over
that.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Nov 20 '08 #27

P: n/a
Dik T. Winter said:
In article <oc******************************@bt.comrj*@see.sig.invalid
writes: ...
No, you were right the first time. It's missing. The behaviour of the
program is consequently undefined (calling a variadic function without
a valid function prototype in scope).

That entry is from the IOCCC of 1987. At that time there was no such
requirement.
Agreed. My comment was with regard to ISO C, which the program pre-dates.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Nov 20 '08 #28

P: n/a
In article <ln************@nuthaus.mib.org>,
Keith Thompson <ks***@mib.orgwrote:
>As recently as gcc 4.3.2 on Ubuntu, "unix" *is* predefined as a macro
with the value 1. I've never heard of ti being an implicitly declared
automatic variable.
And here's an article referring to some commonly predefined macros
in the mid-80s:

http://groups.google.com/group/comp....hl=en&ie=UTF-8

-- Richard
--
Please remember to mention me / in tapes you leave behind.
Nov 20 '08 #29

P: n/a
Nate Eldredge <na**@vulcan.lanwrote:
>
Was it ever possible to implicitly declare *variables*?
Only parameters:

foo(i, j)
{
return i + j;
}

That implicitly declares i and j as int's.
--
Larry Jones

Yep, we'd probably be dead by now if it wasn't for Twinkies. -- Calvin
Nov 20 '08 #30

P: n/a
Nate Eldredge <na**@vulcan.lanwrote:
>
(Language barrier: to me, these characters ( ) are parentheses. Braces
are these { } . These [ ] are brackets.)
Yes, in other dialects they're all brackets: round brackets, curly
brackets, and square brackets, respectively. But I know of no dialect
in which the round ones are called "braces" as the original poster did.
Perhaps he was just using an unfortunate font. :-)
--
Larry Jones

Don't you hate it when your boogers freeze? -- Calvin
Nov 20 '08 #31

P: n/a
la************@siemens.com wrote:
>Was it ever possible to implicitly declare *variables*?

Only parameters:

foo(i, j)
{
return i + j;
}

That implicitly declares i and j as int's.
That's not what Nate's talking about. "Implicitly" in this case means
"without ever mentioning the variable's name in any declaration", as in

foo(i)
{
return a + b + i;
}

This was never possible (at least formally). So the linked explanation
is incorrect, although the idea with the storage for allegedly
implicitly declared 'int unix' overlaying the system-provided 'argc'
storage area had an undeniable perverted attractiveness.

As for the declarations that omit everything besides the name, some
older compiler would accept file-scope declarations without a storage
class and type name. I don't remember whether it was intended to be
legal in "C Reference Manual" times.

--
Best regards,
Andrey Tarasevich
Nov 20 '08 #32

P: n/a
On November 20, 2008 12:26, in comp.lang.c, Andrey Tarasevich
(an**************@hotmail.com) wrote:
la************@siemens.com wrote:
>>Was it ever possible to implicitly declare *variables*?
[snip]
As for the declarations that omit everything besides the name, some
older compiler would accept file-scope declarations without a storage
class and type name. I don't remember whether it was intended to be
legal in "C Reference Manual" times.
As I read it, the "C Reference Manual" requires that declarations have
either a type specifier /or/ a storage class specifier /or/ both. But, you
cannot omit both type specifier and storage class specifier.

"8. Declarations
...
Declarations have the form

declaration:
decl-specifiers declarator-list{opt} ;

The declarators in the declarator list contain the identifiers being
declared. The decl-specifiers consist of a sequence of type and storage
class specifiers.

decl-specifiers:
type-specifier decl-specifiers{opt}
sc-specifier decl-specifiers{opt}

8.1 Storage class specifiers
The sc-specifiers are

sc-specifier:
auto
static
extern
register
typedef

...
At most one sc-specifier may be given in a declaration. If the
sc-specifier is missing from a declaration, it is taken to be auto
inside a function, extern outside. Exception: functions are never
automatic.

8.2 Type specifiers
The type-specifiers are

type-specifier:
char
short
int
long
unsigned
float
double
struct-or-union-specifier
typedef-name

...
If the type-specifier is missing from a declaration, it is taken to be int.
"

--
Lew Pitcher

Master Codewright & JOAT-in-training | Registered Linux User #112576
http://pitcher.digitalfreehold.ca/ | GPG public key available by request
---------- Slackware - Because I know what I'm doing. ------
Nov 20 '08 #33

P: n/a
c.***********@gmail.com wrote:
Can you determine output of following one liner by visual inspection..
It had won an award in obfuscated C contest.....
main() { printf(&unix["\021%six\012\0"],(unix)["have"]+"fun"-060);}
You can also list your favourite one liner...
I get the following when attempting to compile this code:

oneliner.c:1: warning: return type defaults to 'int'
oneliner.c: In function 'main':
oneliner.c:1: warning: implicit declaration of function 'printf'
oneliner.c:1: warning: incompatible implicit declaration of built-in
function 'printf'
oneliner.c:1: error: 'unix' undeclared (first use in this function)
oneliner.c:1: error: (Each undeclared identifier is reported only once
oneliner.c:1: error: for each function it appears in.)
oneliner.c:1: error: stray '\327' in program
oneliner.c:1: error: expected ')' before numeric constant
oneliner.c:1: warning: control reaches end of non-void function

So much for output.
** Posted from http://www.teranews.com **
Nov 21 '08 #34

P: n/a
On Nov 20, 9:38 pm, Eric Schmidt <eric41...@comcast.netwrote:
c.lang.mys...@gmail.com wrote:
Can you determine output of following one liner by visual inspection..
It had won an award in obfuscated C contest.....
main() { printf(&unix["\021%six\012\0"],(unix)["have"]+"fun"-060);}
You can also list your favourite one liner...

I get the following when attempting to compile this code:

oneliner.c:1: warning: return type defaults to 'int'
oneliner.c: In function 'main':
oneliner.c:1: warning: implicit declaration of function 'printf'
oneliner.c:1: warning: incompatible implicit declaration of built-in
function 'printf'
oneliner.c:1: error: 'unix' undeclared (first use in this function)
oneliner.c:1: error: (Each undeclared identifier is reported only once
oneliner.c:1: error: for each function it appears in.)
oneliner.c:1: error: stray '\327' in program
oneliner.c:1: error: expected ')' before numeric constant
oneliner.c:1: warning: control reaches end of non-void function

So much for output.
** Posted fromhttp://www.teranews.com**
The third symbol in "-060" is not an x by a times symbol, this is not
ascii.
What you get if you compile, depends on how you tried to copy the line
and how the compiler you use deals with non-ascii characters
When I did a cut and paste, I got the same errors with gcc 3.2.2

(a lot of error text for a "small" error. This reminds me of the
contest reported by Hofstadter IN GEB in which the smallest
<code text>/<error textratio was desired. Apparently the winner
was a single character "." which when fed to a COBOL compiler
produced pages of output)

- William Hughes
Nov 21 '08 #35

P: n/a
Eric Schmidt <er*******@comcast.netwrites:
c.***********@gmail.com wrote:
>Can you determine output of following one liner by visual inspection..
It had won an award in obfuscated C contest.....
main() { printf(&unix["\021%six\012\0"],(unix)["have"]+"fun"-060);}
You can also list your favourite one liner...

I get the following when attempting to compile this code:

oneliner.c:1: warning: return type defaults to 'int'
oneliner.c: In function 'main':
oneliner.c:1: warning: implicit declaration of function 'printf'
oneliner.c:1: warning: incompatible implicit declaration of built-in
function 'printf'
oneliner.c:1: error: 'unix' undeclared (first use in this function)
oneliner.c:1: error: (Each undeclared identifier is reported only once
oneliner.c:1: error: for each function it appears in.)
oneliner.c:1: error: stray '\327' in program
oneliner.c:1: error: expected ')' before numeric constant
oneliner.c:1: warning: control reaches end of non-void function

So much for output.
The warnings are all about things that weren't necessarily considered
problems in pre-ANSI C. The errors are caused by (a) the fact that
you compiler doesn't pre-define "unix" as a macro, and (b) the
original poster's use of a multiplication symbol rather than a letter
'x' in 0x60.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Nov 21 '08 #36

P: n/a
William Hughes <wp*******@hotmail.comwrites:
(a lot of error text for a "small" error. This reminds me of the
contest reported by Hofstadter IN GEB in which the smallest
<code text>/<error textratio was desired. Apparently the winner
was a single character "." which when fed to a COBOL compiler
produced pages of output)
Fun. I can't seem to find it in my copy of GEB, though.

I was thinking

a.c:
#error
#include "a.c"

would win with a ratio of zero. Unfortunately my compiler has a maximum
level of #include nesting, so I only get a ratio of 22/581994, or
~0.0000378. I suppose you might want to require the smallest *nonzero*
ratio anyway, by analogy with the busy beaver problem.
Nov 21 '08 #37

P: n/a
On Nov 21, 2:03 am, Nate Eldredge <n...@vulcan.lanwrote:
William Hughes <wpihug...@hotmail.comwrites:
(a lot of error text for a "small" error. This reminds me of the
contest reported by Hofstadter IN GEB in which the smallest
<code text>/<error textratio was desired. Apparently the winner
was a single character "." which when fed to a COBOL compiler
produced pages of output)

Fun. I can't seem to find it in my copy of GEB, though.

Well, my copy in not available at the moment. I am pretty
sure I saw this in GEB (an aside in amongst a discussion
of self replicating programs).
>
I was thinking

a.c:
#error
#include "a.c"

would win with a ratio of zero.


Nice. Perfectly within the spirit of GEB, too.

- William Hughes

Nov 21 '08 #38

This discussion thread is closed

Replies have been disabled for this discussion.