Results 1 to 6 of 6

Thread: Why pre-processor gives a space in comments?

  1. #1
    Join Date
    Aug 2009
    Posts
    59

    Why pre-processor gives a space in comments?

    Hello friends,
    I want to write program in c++ language in which I want to comment a line using the pre-processor in the following ways.
    Code:
    #define open 
    #define close
    main()
    {
            // your code 
    }
    In my code when I used $gcc -E filename.c I expected
    Code:
    /* commented line */
    but I got
    Code:
    / * commented line */
    I don't know why pre-processor gives a space in comments? Please help me to fix this problem.

  2. #2
    Join Date
    May 2008
    Posts
    2,012

    Re: Why pre-processor gives a space in comments?

    As per my information pre-processor is used to runs and produces the source code into the machine language code that is understand by C compiler. Pre-processor processes your code only once and for this reason even if you create "/*" using your #define then C compiler would see the "/*" in your code and will give an error message, because it is an invalid code rather it is preprocessing instruction.

  3. #3
    Join Date
    Apr 2008
    Posts
    2,005

    Re: Why pre-processor gives a space in comments?

    I think "#define" is the only preprocessing instruction you have used in your code. As per my information "/*" is not a preprocessor instruction, rather it is used to define comments. The main work of preprocessor is that, it used to remove comments before passing the source code to the c- compiler. I think comments are used as whitespace and not an preprocessing tokens.

  4. #4
    Join Date
    May 2008
    Posts
    2,297

    Re: Why pre-processor gives a space in comments?

    As per GNU C Preprocessor documentation 2 tokens which used one valid token can not be pasted together. It means that you can not concatenate "y" with "+" in either order. If you accidentally tried this then you will get an error message. It unnecessarily put concatenate x with + in either order. It also use '##' in complex macros unnecessarily. If you get an error message then you have to remove '##' from your code to fix this problem.

  5. #5
    Join Date
    Nov 2005
    Posts
    1,323

    Re: Why pre-processor gives a space in comments?

    You get an error because "/*" is not a valid token. As per my information 2 tokens which are not form valid token cannot be pasted together. As per my information "##" is unnecessarily used to avoid creating a comment and avoid confusion. To fix this problem Avoid comment headers because they already used in stage 3. To fix this problem you have to use following code:
    Code:
    if ((*plhss)->types == CPPs_DIVs && rhss->types != CPPs_EQs)
            *ends++ = ' ';

  6. #6
    Join Date
    Oct 2005
    Posts
    2,393

    Re: Why pre-processor gives a space in comments?

    If you want to comment your source code using pre-processor then you have to use following code:
    Code:
    #if 0
    ...
    #endif
    This is used to replace comments with spaces before preprocessor runs. If you put / and * characters together, then you will get /* which is called as couple operators.

Similar Threads

  1. Can't view comments on my ipad
    By AARON Carter in forum Portable Devices
    Replies: 3
    Last Post: 01-10-2010, 10:20 AM
  2. How to include comments in HTML
    By rooki in forum Software Development
    Replies: 5
    Last Post: 25-12-2009, 01:06 PM
  3. Comments on the images
    By StarTraveller in forum Customize Desktop
    Replies: 1
    Last Post: 28-11-2008, 07:28 PM
  4. Add comments inside Powershell
    By Bruno Guerpillon in forum Windows Server Help
    Replies: 1
    Last Post: 07-02-2007, 05:05 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,939,189.26807 seconds with 17 queries