Standard Behavior Of An Empty Macro Preceding A Preprocessing Directive












0














Take, for example, the following:



#define FOO
FOO #define BAR 1
BAR


What should, according to each of the ANSI C and C99 standards, be the preprocessed output of the above code?



It seems to me that this should be evaluated to 1; however, running the above example through both gcc -E and clang -E produces the following:



    #define BAR 1
BAR









share|improve this question






















  • # should be the first non-space character in a line with directive, otherwise it gets ignored
    – qrdl
    Nov 18 '18 at 8:00












  • @qrdl: it does not get ignored: it will produce an error because # is not a valid token after preprocessing.
    – rici
    Nov 18 '18 at 8:08










  • @rici Obviously compiler will complain about it, but OP is talking just about CPP here, and CPP ignores it.
    – qrdl
    Nov 18 '18 at 8:11
















0














Take, for example, the following:



#define FOO
FOO #define BAR 1
BAR


What should, according to each of the ANSI C and C99 standards, be the preprocessed output of the above code?



It seems to me that this should be evaluated to 1; however, running the above example through both gcc -E and clang -E produces the following:



    #define BAR 1
BAR









share|improve this question






















  • # should be the first non-space character in a line with directive, otherwise it gets ignored
    – qrdl
    Nov 18 '18 at 8:00












  • @qrdl: it does not get ignored: it will produce an error because # is not a valid token after preprocessing.
    – rici
    Nov 18 '18 at 8:08










  • @rici Obviously compiler will complain about it, but OP is talking just about CPP here, and CPP ignores it.
    – qrdl
    Nov 18 '18 at 8:11














0












0








0







Take, for example, the following:



#define FOO
FOO #define BAR 1
BAR


What should, according to each of the ANSI C and C99 standards, be the preprocessed output of the above code?



It seems to me that this should be evaluated to 1; however, running the above example through both gcc -E and clang -E produces the following:



    #define BAR 1
BAR









share|improve this question













Take, for example, the following:



#define FOO
FOO #define BAR 1
BAR


What should, according to each of the ANSI C and C99 standards, be the preprocessed output of the above code?



It seems to me that this should be evaluated to 1; however, running the above example through both gcc -E and clang -E produces the following:



    #define BAR 1
BAR






c c-preprocessor preprocessor






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 18 '18 at 7:50









jinscoe123jinscoe123

17912




17912












  • # should be the first non-space character in a line with directive, otherwise it gets ignored
    – qrdl
    Nov 18 '18 at 8:00












  • @qrdl: it does not get ignored: it will produce an error because # is not a valid token after preprocessing.
    – rici
    Nov 18 '18 at 8:08










  • @rici Obviously compiler will complain about it, but OP is talking just about CPP here, and CPP ignores it.
    – qrdl
    Nov 18 '18 at 8:11


















  • # should be the first non-space character in a line with directive, otherwise it gets ignored
    – qrdl
    Nov 18 '18 at 8:00












  • @qrdl: it does not get ignored: it will produce an error because # is not a valid token after preprocessing.
    – rici
    Nov 18 '18 at 8:08










  • @rici Obviously compiler will complain about it, but OP is talking just about CPP here, and CPP ignores it.
    – qrdl
    Nov 18 '18 at 8:11
















# should be the first non-space character in a line with directive, otherwise it gets ignored
– qrdl
Nov 18 '18 at 8:00






# should be the first non-space character in a line with directive, otherwise it gets ignored
– qrdl
Nov 18 '18 at 8:00














@qrdl: it does not get ignored: it will produce an error because # is not a valid token after preprocessing.
– rici
Nov 18 '18 at 8:08




@qrdl: it does not get ignored: it will produce an error because # is not a valid token after preprocessing.
– rici
Nov 18 '18 at 8:08












@rici Obviously compiler will complain about it, but OP is talking just about CPP here, and CPP ignores it.
– qrdl
Nov 18 '18 at 8:11




@rici Obviously compiler will complain about it, but OP is talking just about CPP here, and CPP ignores it.
– qrdl
Nov 18 '18 at 8:11












3 Answers
3






active

oldest

votes


















1














The draft standard "ISO/IEC 9899:201x Committee Draft — April 12, 2011 N1570" section 6.10 actually contains an example of this:




EXAMPLE In:



#define EMPTY 
EMPTY # include <file.h>


the sequence of preprocessing tokens on the second line is not a preprocessing directive, because it does not begin with a # at the start of translation phase 4, even though it will do so after the macro EMPTY has been replaced.




It tells us that "... the second line is not a preprocessing directive ..."



So for your code



FOO #define BAR 1


is not a preprocessing directive meaning that only FOO will be replaced and BAR will not be defined. Consequently the output of the preprocessor is:



 #define BAR 1
BAR





share|improve this answer





























    1














    Your code is not valid



    ISO/IEC 9899:2011, Section 6.10 Preprocessing directives:




    A preprocessing directive consists of a sequence of preprocessing
    tokens that satisfies the following constraints: The first token in
    the sequence is a # preprocessing token
    that (at the start of
    translation phase 4) is either the first character in the source file
    (optionally after white space containing no new-line characters) or
    that follows white space containing at least one new-line character.







    share|improve this answer





























      0














      This example actually occurs in the Standard (C17 6.10/8):




      EXAMPLE In:



      #define EMPTY
      EMPTY # include <file.h>


      the sequence of preprocessing tokens on the second line is not a preprocessing directive, because it does not begin with a # at the start of translation phase 4, even though it will do so after the macro EMPTY has been replaced.




      So the output you see from gcc -E is correct. (Note: the amount of whitespace here is not significant , at that stage of translation the program has been translated to a sequence of preprocessing tokens; the different amounts of whitespace in the output is just an artefact of how gcc -E works).






      share|improve this answer





















      • Thank you as well, but, unfortunately, I can only accept one answer, and 4386427 was too quick. :)
        – jinscoe123
        Nov 18 '18 at 8:39











      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53358884%2fstandard-behavior-of-an-empty-macro-preceding-a-preprocessing-directive%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      1














      The draft standard "ISO/IEC 9899:201x Committee Draft — April 12, 2011 N1570" section 6.10 actually contains an example of this:




      EXAMPLE In:



      #define EMPTY 
      EMPTY # include <file.h>


      the sequence of preprocessing tokens on the second line is not a preprocessing directive, because it does not begin with a # at the start of translation phase 4, even though it will do so after the macro EMPTY has been replaced.




      It tells us that "... the second line is not a preprocessing directive ..."



      So for your code



      FOO #define BAR 1


      is not a preprocessing directive meaning that only FOO will be replaced and BAR will not be defined. Consequently the output of the preprocessor is:



       #define BAR 1
      BAR





      share|improve this answer


























        1














        The draft standard "ISO/IEC 9899:201x Committee Draft — April 12, 2011 N1570" section 6.10 actually contains an example of this:




        EXAMPLE In:



        #define EMPTY 
        EMPTY # include <file.h>


        the sequence of preprocessing tokens on the second line is not a preprocessing directive, because it does not begin with a # at the start of translation phase 4, even though it will do so after the macro EMPTY has been replaced.




        It tells us that "... the second line is not a preprocessing directive ..."



        So for your code



        FOO #define BAR 1


        is not a preprocessing directive meaning that only FOO will be replaced and BAR will not be defined. Consequently the output of the preprocessor is:



         #define BAR 1
        BAR





        share|improve this answer
























          1












          1








          1






          The draft standard "ISO/IEC 9899:201x Committee Draft — April 12, 2011 N1570" section 6.10 actually contains an example of this:




          EXAMPLE In:



          #define EMPTY 
          EMPTY # include <file.h>


          the sequence of preprocessing tokens on the second line is not a preprocessing directive, because it does not begin with a # at the start of translation phase 4, even though it will do so after the macro EMPTY has been replaced.




          It tells us that "... the second line is not a preprocessing directive ..."



          So for your code



          FOO #define BAR 1


          is not a preprocessing directive meaning that only FOO will be replaced and BAR will not be defined. Consequently the output of the preprocessor is:



           #define BAR 1
          BAR





          share|improve this answer












          The draft standard "ISO/IEC 9899:201x Committee Draft — April 12, 2011 N1570" section 6.10 actually contains an example of this:




          EXAMPLE In:



          #define EMPTY 
          EMPTY # include <file.h>


          the sequence of preprocessing tokens on the second line is not a preprocessing directive, because it does not begin with a # at the start of translation phase 4, even though it will do so after the macro EMPTY has been replaced.




          It tells us that "... the second line is not a preprocessing directive ..."



          So for your code



          FOO #define BAR 1


          is not a preprocessing directive meaning that only FOO will be replaced and BAR will not be defined. Consequently the output of the preprocessor is:



           #define BAR 1
          BAR






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 18 '18 at 8:30









          43864274386427

          20.5k31845




          20.5k31845

























              1














              Your code is not valid



              ISO/IEC 9899:2011, Section 6.10 Preprocessing directives:




              A preprocessing directive consists of a sequence of preprocessing
              tokens that satisfies the following constraints: The first token in
              the sequence is a # preprocessing token
              that (at the start of
              translation phase 4) is either the first character in the source file
              (optionally after white space containing no new-line characters) or
              that follows white space containing at least one new-line character.







              share|improve this answer


























                1














                Your code is not valid



                ISO/IEC 9899:2011, Section 6.10 Preprocessing directives:




                A preprocessing directive consists of a sequence of preprocessing
                tokens that satisfies the following constraints: The first token in
                the sequence is a # preprocessing token
                that (at the start of
                translation phase 4) is either the first character in the source file
                (optionally after white space containing no new-line characters) or
                that follows white space containing at least one new-line character.







                share|improve this answer
























                  1












                  1








                  1






                  Your code is not valid



                  ISO/IEC 9899:2011, Section 6.10 Preprocessing directives:




                  A preprocessing directive consists of a sequence of preprocessing
                  tokens that satisfies the following constraints: The first token in
                  the sequence is a # preprocessing token
                  that (at the start of
                  translation phase 4) is either the first character in the source file
                  (optionally after white space containing no new-line characters) or
                  that follows white space containing at least one new-line character.







                  share|improve this answer












                  Your code is not valid



                  ISO/IEC 9899:2011, Section 6.10 Preprocessing directives:




                  A preprocessing directive consists of a sequence of preprocessing
                  tokens that satisfies the following constraints: The first token in
                  the sequence is a # preprocessing token
                  that (at the start of
                  translation phase 4) is either the first character in the source file
                  (optionally after white space containing no new-line characters) or
                  that follows white space containing at least one new-line character.








                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 18 '18 at 8:01









                  Keine LustKeine Lust

                  26.8k43363




                  26.8k43363























                      0














                      This example actually occurs in the Standard (C17 6.10/8):




                      EXAMPLE In:



                      #define EMPTY
                      EMPTY # include <file.h>


                      the sequence of preprocessing tokens on the second line is not a preprocessing directive, because it does not begin with a # at the start of translation phase 4, even though it will do so after the macro EMPTY has been replaced.




                      So the output you see from gcc -E is correct. (Note: the amount of whitespace here is not significant , at that stage of translation the program has been translated to a sequence of preprocessing tokens; the different amounts of whitespace in the output is just an artefact of how gcc -E works).






                      share|improve this answer





















                      • Thank you as well, but, unfortunately, I can only accept one answer, and 4386427 was too quick. :)
                        – jinscoe123
                        Nov 18 '18 at 8:39
















                      0














                      This example actually occurs in the Standard (C17 6.10/8):




                      EXAMPLE In:



                      #define EMPTY
                      EMPTY # include <file.h>


                      the sequence of preprocessing tokens on the second line is not a preprocessing directive, because it does not begin with a # at the start of translation phase 4, even though it will do so after the macro EMPTY has been replaced.




                      So the output you see from gcc -E is correct. (Note: the amount of whitespace here is not significant , at that stage of translation the program has been translated to a sequence of preprocessing tokens; the different amounts of whitespace in the output is just an artefact of how gcc -E works).






                      share|improve this answer





















                      • Thank you as well, but, unfortunately, I can only accept one answer, and 4386427 was too quick. :)
                        – jinscoe123
                        Nov 18 '18 at 8:39














                      0












                      0








                      0






                      This example actually occurs in the Standard (C17 6.10/8):




                      EXAMPLE In:



                      #define EMPTY
                      EMPTY # include <file.h>


                      the sequence of preprocessing tokens on the second line is not a preprocessing directive, because it does not begin with a # at the start of translation phase 4, even though it will do so after the macro EMPTY has been replaced.




                      So the output you see from gcc -E is correct. (Note: the amount of whitespace here is not significant , at that stage of translation the program has been translated to a sequence of preprocessing tokens; the different amounts of whitespace in the output is just an artefact of how gcc -E works).






                      share|improve this answer












                      This example actually occurs in the Standard (C17 6.10/8):




                      EXAMPLE In:



                      #define EMPTY
                      EMPTY # include <file.h>


                      the sequence of preprocessing tokens on the second line is not a preprocessing directive, because it does not begin with a # at the start of translation phase 4, even though it will do so after the macro EMPTY has been replaced.




                      So the output you see from gcc -E is correct. (Note: the amount of whitespace here is not significant , at that stage of translation the program has been translated to a sequence of preprocessing tokens; the different amounts of whitespace in the output is just an artefact of how gcc -E works).







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Nov 18 '18 at 8:32









                      M.MM.M

                      104k11114234




                      104k11114234












                      • Thank you as well, but, unfortunately, I can only accept one answer, and 4386427 was too quick. :)
                        – jinscoe123
                        Nov 18 '18 at 8:39


















                      • Thank you as well, but, unfortunately, I can only accept one answer, and 4386427 was too quick. :)
                        – jinscoe123
                        Nov 18 '18 at 8:39
















                      Thank you as well, but, unfortunately, I can only accept one answer, and 4386427 was too quick. :)
                      – jinscoe123
                      Nov 18 '18 at 8:39




                      Thank you as well, but, unfortunately, I can only accept one answer, and 4386427 was too quick. :)
                      – jinscoe123
                      Nov 18 '18 at 8:39


















                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.





                      Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                      Please pay close attention to the following guidance:


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53358884%2fstandard-behavior-of-an-empty-macro-preceding-a-preprocessing-directive%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      How to send String Array data to Server using php in android

                      Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

                      Is anime1.com a legal site for watching anime?