#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?

1

There are 1 answers

0
Sparkette On BEST ANSWER

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.