Asked on Stack Overflow, but they suggested to move it here

A while ago I was reading about quines. It made me wonder if it possible to write a macro in C which will print itself, without writing any function such as main. every piece of code should be only in macro. After a few attempts, I couldn't find the solution.

While searching the web for answer, I found the following code:

#define Q(x) #x;x
char *q=Q(main(){printf("#define Q(x) #x;x\nchar *q=Q(");printf(q);printf(")\n");})

Although part of the code isn't in the #define (isn't macro). Is it possible to implement a macro which will print the program ( quine type program )?

EDIT: if it isn't possible (because the macros are 'made' in the preprocessor step), is it possible to implement a quine which is mostly in macros?


closed as unclear what you're asking by FryAmTheEggman, Timtech, pajonk, l4m2, Toto May 18 '18 at 6:29

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 5
    \$\begingroup\$ @Picard This is on topic, and it's not a duplicate. It is similar in style to this question. \$\endgroup\$ – mbomb007 May 17 '18 at 13:42
  • 4
    \$\begingroup\$ @mbomb007 How did you come to that conclusion? Of all the answers to Let's decide what kind of non-challenge questions we want once and for all, only Requests for lists of language-specific golfing advice and Questions about improving code golf / code challenge skills have a positive score. \$\endgroup\$ – Dennis May 17 '18 at 14:04
  • 14
    \$\begingroup\$ Since no one else has yet said it, welcome to PPCG! You seem to have stirred up the hornet's nest with your first post (which isn't necessarily a bad thing!), so hopefully you'll stick around for the next one! \$\endgroup\$ – AdmBorkBork May 17 '18 at 14:37
  • 2
    \$\begingroup\$ define "mostly in macros" \$\endgroup\$ – ASCII-only May 18 '18 at 1:02
  • 3
    \$\begingroup\$ @mbomb007 Ignoring whether it's on-topic, it's definitely unclear. Macros can't print. The question needs more clarification from the OP before it can be reopened. \$\endgroup\$ – user202729 May 18 '18 at 3:19

Browse other questions tagged or ask your own question.