-1
#include <stdio.h>

extern const char source[];

int main()
{
    printf("%s", source);
    return 0;
}

asm(
    ".section .rodata\n"
    ".global source\n"
    "source:\n"
    ".incbin \"" __FILE__ "\"\n"
    ".byte 0\n"
);

Wikipedia says a quine receives no input, and I know that, for this reason, a program which reads its own source code from a file doesn't count. The above program does simply read its own source code and print it to standard output, but it's part of the program itself. Traditional quines also typically have strings embedded in the same place, perhaps even the entire source code/output if there's a particularly aggressive optimizer involved.

This program does load its source code from the file to display it...but it does so at compile time, so the program still doesn't take input. So is it a quine or not?

flarn2006
  • 1,787
  • 15
  • 37
  • The real question is: **is your code a genuine C program? It might not be.** Read [n1570](https://web.cs.dal.ca/~vlado/pl/C_Standard_2011-n1570.pdf) to check. Did you try to compile it on an Android tablet, or a PowerPC Linux workstation, or a [RaspberryPi](http://raspberrypi.org/), or an [IBM Z](https://en.wikipedia.org/wiki/IBM_Z) mainframe ? – Basile Starynkevitch Sep 10 '20 at 19:06
  • No, it is not. Because you read the source code. It would be one when you print the whole elf file since the compiled version does not read anything. But your code reads something, even when it is while compiling, and you only display the code given to the compiler. – 12431234123412341234123 Sep 10 '20 at 19:09
  • Whether it technically is a quine or not, it certainly doesn't meet the spirit of a quine. – Raymond Chen Sep 10 '20 at 19:29
  • Your program accesses its own source stored in a file at compile time, which is no different from doing the same thing at run time. [And it doesn't work, so there](http://coliru.stacked-crooked.com/a/bf6880e448cd3217). – n. m. could be an AI Sep 10 '20 at 21:28
  • In all seriousness, there's no official written-in-stone definition of a quine. You can make up your own definition. Would you make and publish a definition that deliberately admits this program? Say you are organising a high school quine competition, and you get to write the rules. It boils down to what kind of skills you find valuable and want to encourage. – n. m. could be an AI Sep 10 '20 at 21:47
  • Thanks for all your feedback :) If none of you post an answer, I'll post one of my own summarizing what you said. I think you especially should, @12431234123412341234123; you have a really good point. About how compile-time reading counts because the code that's printed is the source code form. – flarn2006 Sep 11 '20 at 01:07

1 Answers1

0

Based on the comments I've received, my understanding is that no, it wouldn't be considered a quine in the usual sense.

The strongest point, I think, is the one made by @12431234123412341234123: once the program is compiled, the compiled form cannot be said to output itself, as "itself" is a binary, and it outputs C source code. So the compiled binary wouldn't be a quine anyway. The source code wouldn't be either, because the .incbin line loads the source code from the file. (It doesn't matter that it happens at compile time, because the source code needs to be compiled in order to be run.)

Regardless, (as @Raymond Chen pointed out) it doesn't fit the spirit of a quine, and (as @n. 'pronouns' m. pointed out) there's no definite "letter of the law" for it to fit either. More than anything else it depends on the definition you're using.

flarn2006
  • 1,787
  • 15
  • 37