Thread: Blank line within a #define

  1. #1
    Registered User
    Join Date
    Sep 2012
    Posts
    4

    Blank line within a #define

    I'm looking at some code that I did not write. As far as I know this code compiles but I don't know what compiler (I think it is CCS ... an embedded systems compiler by Texas Instruments).

    Here is what I see in the code:

    #define THIS_THING \

    0x1234

    Notice the space after the #define line. Is that valid in some compilers?

  2. #2
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    If you want the blank line to be part of the macro, you need to add a '\' character.
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

  3. #3
    Registered User
    Join Date
    Apr 2015
    Location
    Bangalore, Karnataka, India
    Posts
    34
    Quote Originally Posted by eddyq View Post

    Here is what I see in the code:

    #define THIS_THING \

    0x1234

    Notice the space after the #define line. Is that valid in some compilers?
    Although I don't have any proof to validate my statement but I believe yes it is accepted in some compilers.

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    I recommend that you post code in [code][/code] bbcode tags.

    I do not know if any compilers accept what you showed, but with respect to the standard:
    Quote Originally Posted by C11 Clause 5.1.1.2 Paragraph 2
    Each instance of a backslash character (\) immediately followed by a new-line character is deleted, splicing physical source lines to form logical source lines. Only the last backslash on any physical source line shall be eligible for being part of such a splice. A source file that is not empty shall end in a new-line character, which shall not be immediately preceded by a backslash character before any such splicing takes place.
    Since the newline (as in logical source lines) ends the macro, the blank line in between means that the syntax is invalid according to the standard.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Terminating input upon encountering a blank line
    By thames in forum C++ Programming
    Replies: 7
    Last Post: 12-21-2012, 12:00 PM
  2. Search for Blank Line
    By uconnhuskies in forum C Programming
    Replies: 9
    Last Post: 07-21-2011, 08:09 PM
  3. Reading a file containing a blank line
    By maniac123 in forum C++ Programming
    Replies: 8
    Last Post: 01-27-2011, 11:42 AM
  4. Replies: 3
    Last Post: 04-27-2005, 11:50 AM
  5. testing for blank line
    By rippascal in forum C++ Programming
    Replies: 3
    Last Post: 03-20-2002, 09:50 PM

Tags for this Thread