The Classic C Quine (2003)
susam.in
susam.in
This is an Excel macro that is self-aware: it only tries to print itself if it is a quine.
It's sensitive to whitespace, so I provided the pastebin link above.
Sub selfCheckingExcelQuine()
s = "Sub selfCheckingExcelQuine()\ s = ~\ result = Replace(Replace(Replace(s, Chr(36), Chr(34)), Chr(92), vbCrLf), Chr(126), Chr(34) & s & Chr(34))\ \ If myText() = result Then\ Debug.Print result\ Else\ Debug.Print $Not a quine!$\ End If\End Sub\\Function myText()\ Dim p As VBProject: Set p = ThisWorkbook.VBProject\ Dim m As CodeModule: Set m = p.VBComponents(p.VBE.SelectedVBComponent.Name).CodeModule\ \ myText = m.Lines(1, m.CountOfLines)\End Function\"
result = Replace(Replace(Replace(s, Chr(36), Chr(34)), Chr(92), vbCrLf), Chr(126), Chr(34) & s & Chr(34))
If myText() = result Then
Debug.Print result
Else
Debug.Print "Not a quine!"
End If
End Sub
Function myText()
Dim p As VBProject: Set p = ThisWorkbook.VBProject
Dim m As CodeModule: Set m = p.VBComponents(p.VBE.SelectedVBComponent.Name).CodeModule
myText = m.Lines(1, m.CountOfLines)
End FunctionThat is undefined behaviour! (https://port70.net/~nsz/c/c11/n1570.html#J.2)