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

Quine

P: n/a
Hi,
I have come across a term, it is Quine.

"In computing, a quine is a program (a form of metaprogram) that
produces its complete source code as its only output. For amusement,
hackers sometimes attempt to develop the shortest possible quine in
any given programming language."

Can anyone explain me what does it exactly mean? And is there
someone's self defined quine for some language.

Mar 20 '07 #1
Share this Question
Share on Google+
11 Replies


P: n/a
Hi,
I have come across a term, it is Quine.

"In computing, a quine is a program (a form of metaprogram) that
produces its complete source code as its only output. For amusement,
hackers sometimes attempt to develop the shortest possible quine in
any given programming language."

Can anyone explain me what does it exactly mean? And is there
someone's self defined quine for some language.
It is program that show it's source:

main(a){a="main(a){a=%c%s%c;printf(a,34,a,34);}";p rintf(a,34,a,34);}

will display

main(a){a="main(a){a=%c%s%c;printf(a,34,a,34);}";p rintf(a,34,a,34);}

Best,
zaharije Pasalic

Mar 20 '07 #2

P: n/a
On Mar 20, 1:13 pm, pasalic.zahar...@gmail.com wrote:
(>written by singlepoint, atttribution line was snipped by >-
poster)
Hi,
I have come across a term, it is Quine.
"In computing, a quine is a program (a form of metaprogram) that
produces its complete source code as its only output. For amusement,
hackers sometimes attempt to develop the shortest possible quine in
any given programming language."
Can anyone explain me what does it exactly mean? And is there
someone's self defined quine for some language.

It is program that show it's source:

main(a){a="main(a){a=%c%s%c;printf(a,34,a,34);}";p rintf(a,34,a,34);}

will display

main(a){a="main(a){a=%c%s%c;printf(a,34,a,34);}";p rintf(a,34,a,34);}
This won't necessarily work, because '\"' isn't necessarily equal to
34.
This probably won't work, because printf hasn't been declared and it
uses a variable-length argument list.

Google found me <http://www.madore.org/~david/computers/quine.html>,
which contains what appears to be a strictly-C89-conforming quine
(although it has some that assume ASCII lower down).
--
ais523

Mar 20 '07 #3

P: n/a
"ais523" <ai****@bham.ac.ukwrites:
On Mar 20, 1:13 pm, pasalic.zahar...@gmail.com wrote:
(>written by singlepoint, atttribution line was snipped by >-
poster)
I have come across a term, it is Quine.
"In computing, a quine is a program (a form of metaprogram) that
produces its complete source code as its only output. For amusement,
hackers sometimes attempt to develop the shortest possible quine in
any given programming language."
Can anyone explain me what does it exactly mean? And is there
someone's self defined quine for some language.

It is program that show it's source:

main(a){a="main(a){a=%c%s%c;printf(a,34,a,34);}"; printf(a,34,a,34);}

will display

main(a){a="main(a){a=%c%s%c;printf(a,34,a,34);}"; printf(a,34,a,34);}
This won't necessarily work, because '\"' isn't necessarily equal to
34.
This probably won't work, because printf hasn't been declared and it
uses a variable-length argument list.
[...]

It *probably* will work, because many compilers use a calling
convention that allows variadic functions to work properly even
without a visible prototype (for historical reasons going back to the
days before prototypes were invented).

Note the emphasis on the word "probably". Calling printf, or any
variadic function, with no visible prototype invokes undefined
behavior, and there are undoubtedly implementations where it won't
work. It just happens that a common consequence of the undefined
behavior in this particular case is that the program behaves as it
would if there were a prototype.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Mar 20 '07 #4

P: n/a
jxh
On Mar 20, 8:09 am, "ais523" <ais...@bham.ac.ukwrote:
Google found me <http://www.madore.org/~david/computers/quine.html>,
which contains what appears to be a strictly-C89-conforming quine ...

If C89 is all you need:

#define q(k)main(){return!puts(#k"\nq("#k")");}
q(#define q(k)main(){return!puts(#k"\nq("#k")");})

-- James

Mar 20 '07 #5

P: n/a
jxh wrote:
On Mar 20, 8:09 am, "ais523" <ais...@bham.ac.ukwrote:
Google found me <http://www.madore.org/~david/computers/quine.html>,
which contains what appears to be a strictly-C89-conforming quine ...

If C89 is all you need:

#define q(k)main(){return!puts(#k"\nq("#k")");}
q(#define q(k)main(){return!puts(#k"\nq("#k")");})
You can trivially make it acceptable under both C89 and C99:

#define q(k)int puts();int main(){return!puts(#k"\nq("#k")");}
q(#define q(k)int puts();int main(){return!puts(#k"\nq("#k")");})

Note that puts accepts a parameter of type const char *, not char *.
Yet interestingly, this appears to be valid, because there is special
permission to call an unprototyped function with an argument with a
non-matching type, if argument and parameter type are pointers to
differently qualified versions of char.

That is,

void f();
void g();
int main(void) {
char c;
int i;
f(&c); /* defined behaviour, even though it calls f with char *,
not const char * */
g(&i); /* undefined behaviour, because it calls g with int *, not
const int * */
}
void f(const char *p) {}
void g(const int *p) {}

Mar 20 '07 #6

P: n/a
jxh
On Mar 20, 1:44 pm, "Harald van Dijk" <true...@gmail.comwrote:
jxh wrote:
#define q(k)main(){return!puts(#k"\nq("#k")");}
q(#define q(k)main(){return!puts(#k"\nq("#k")");})

You can trivially make it acceptable under both C89 and C99:

#define q(k)int puts();int main(){return!puts(#k"\nq("#k")");}
q(#define q(k)int puts();int main(){return!puts(#k"\nq("#k")");})

Note that puts accepts a parameter of type const char *, not char *.
Yet interestingly, this appears to be valid, because there is special
permission to call an unprototyped function with an argument with a
non-matching type, if argument and parameter type are pointers to
differently qualified versions of char.
Interesting. Do you have a citation for this? Is it limited to char?
Is void* considered a version of char*?

-- James

Mar 20 '07 #7

P: n/a
jxh wrote:
On Mar 20, 1:44 pm, "Harald van Dijk" <true...@gmail.comwrote:
jxh wrote:
#define q(k)main(){return!puts(#k"\nq("#k")");}
q(#define q(k)main(){return!puts(#k"\nq("#k")");})
You can trivially make it acceptable under both C89 and C99:

#define q(k)int puts();int main(){return!puts(#k"\nq("#k")");}
q(#define q(k)int puts();int main(){return!puts(#k"\nq("#k")");})

Note that puts accepts a parameter of type const char *, not char *.
Yet interestingly, this appears to be valid, because there is special
permission to call an unprototyped function with an argument with a
non-matching type, if argument and parameter type are pointers to
differently qualified versions of char.

Interesting. Do you have a citation for this? Is it limited to char?
Is void* considered a version of char*?
For pointer types, it's limited to char, signed char, unsigned char,
and void.

6.5.2.2p6:
"[...] If the function is defined with a type that does not include a
prototype, and the types of the arguments after promotion are not
compatible with those of the parameters after promotion, the behavior
is undefined, except for the following cases:
— one promoted type is a signed integer type, the other promoted type
is the corresponding unsigned integer type, and the value is
representable in both types;
— both types are pointers to qualified or unqualifiedversions of a
character type or void."

Actually, reading it literally (which I'm not sure is the intent), the
standard doesn't specify whether this applies to puts. If it doesn't,
the behaviour is undefined by omission of any definition of the
behaviour. The text states "If the function is defined with a type
that does not include a prototype, [...]", and the standard does not
specify how puts e.a. are defined.

Mar 20 '07 #8

P: n/a
In article <11**********************@n76g2000hsh.googlegroups .com>,
=?utf-8?B?SGFyYWxkIHZhbiBExLNr?= <tr*****@gmail.comwrote:
>6=2E5.2.2p6:
"[...] If the function is de=EF=AC=81ned with a type that does not include a
prototype, and the types of the arguments after promotion are not
compatible with those of the parameters after promotion, the behavior
is unde=EF=AC=81ned, except for the following cases:
Is the standard really written in terms of the f-i ligature
instead of seperate f and i characters? Use of the ligature
makes it hard to read the text -- it isn't even one of the
latin-8 characters :(
--
Prototypes are supertypes of their clones. -- maplesoft
Mar 20 '07 #9

P: n/a
"singlepoint" <singlepo...@gmail.comwrote:
Hi,
I have come across a term, it is Quine.

"In computing, a quine is a program (a form of metaprogram) that
produces its complete source code as its only output. For amusement,
hackers sometimes attempt to develop the shortest possible quine in
any given programming language."

Can anyone explain me what does it exactly mean?
Do you have a C question?
And is there someone's self defined quine for some language.
Have you tried Google?

--
Peter

Mar 20 '07 #10

P: n/a
ro******@ibd.nrc-cnrc.gc.ca (Walter Roberson) writes:
In article <11**********************@n76g2000hsh.googlegroups .com>,
=?utf-8?B?SGFyYWxkIHZhbiBExLNr?= <tr*****@gmail.comwrote:
>>6=2E5.2.2p6:
"[...] If the function is de=EF=AC=81ned with a type that does not include a
prototype, and the types of the arguments after promotion are not
compatible with those of the parameters after promotion, the behavior
is unde=EF=AC=81ned, except for the following cases:

Is the standard really written in terms of the f-i ligature
instead of seperate f and i characters? Use of the ligature
makes it hard to read the text -- it isn't even one of the
latin-8 characters :(
Copy-and-paste from the C99 standard:

If the function is defined with a type that includes a prototype,
and either the prototype ends with an ellipsis

Copy-and-paste from n1124.pdf:

If the function is defined with a type that includes a prototype,
and either the prototype ends with an ellipsis

The f-i ligatures certainly do appear on my screen when I view the PDF
files (using Adobe Reader 8 under Windows XP), but they're properly
rendered as the two letters "fi" when I copy-and-paste.

I've definitely had ligatures show up oddly in the past (and I've
always manually corrected them). My guess is that the problem went
away when I updated by Adobe Reader to a more recent version; I
haven't kept track well enough to know what fixed it.

I would recommend that anyone having this problem try updating their
software to see if it fixes it, and if it doesn't, please take the
time to manually correct the funny characters before posting. (Though
if your newsreader's editor displays ligatures as ligatures, tracking
them down may be difficult; I use a plain-text newsreader myself.)

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Mar 21 '07 #11

P: n/a
Walter Roberson wrote:
In article <11**********************@n76g2000hsh.googlegroups .com>,
=?utf-8?B?SGFyYWxkIHZhbiBExLNr?= <tr*****@gmail.comwrote:
6=2E5.2.2p6:
"[...] If the function is de=EF=AC=81ned with a type that does not include a
prototype, and the types of the arguments after promotion are not
compatible with those of the parameters after promotion, the behavior
is unde=EF=AC=81ned, except for the following cases:

Is the standard really written in terms of the f-i ligature
instead of seperate f and i characters? Use of the ligature
makes it hard to read the text -- it isn't even one of the
latin-8 characters :(
It depends on the viewer. When I copy and paste from n1124.pdf using
kpdf, I get that, and when I run `pdftotext -layout n1124.pdf`, those
characters are put in the resulting text file. When I copy and paste
using Foxit, it spells it as "fi". Normally I try to remember to
manually edit the text after copying. This time I forgot. Sorry for
the inconvenience.

Mar 21 '07 #12

This discussion thread is closed

Replies have been disabled for this discussion.