Quine

S

singlepoint

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.
 
P

pasalic.zaharije

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);}";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);}

Best,
zaharije Pasalic
 
A

ais523

On Mar 20, 1:13 pm, (e-mail address removed) wrote:
(>> written by singlepoint, atttribution line was snipped by >-
poster)
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.

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).
 
K

Keith Thompson

ais523 said:
On Mar 20, 1:13 pm, (e-mail address removed) wrote:
(>> written by singlepoint, atttribution line was snipped by >-
poster)
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.
 
G

Guest

jxh said:
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) {}
 
J

jxh

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
 
G

Guest

jxh said:
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 deï¬ned 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ï¬ned, 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 qualiï¬ed or unqualiï¬ed versions 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.
 
W

Walter Roberson

=?utf-8?B?SGFyYWxkIHZhbiBExLNr?= said:
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 :(
 
P

Peter Nilsson

singlepoint said:
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?
 
K

Keith Thompson

=?utf-8?B?SGFyYWxkIHZhbiBExLNr?= said:
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.)
 
G

Guest

Walter said:
=?utf-8?B?SGFyYWxkIHZhbiBExLNr?= said:
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.
 

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,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top