Thread: How to create a compound literal for maximum compatibility

  1. #1
    Registered User
    Join Date
    Feb 2011
    Posts
    144

    How to create a compound literal for maximum compatibility

    Hi all. One can create a long string literal like this:

    Code:
    char *mystring = "This is all one"
    " string";
    or:

    Code:
    char *mystring = "This is all one\
     string";
    C99 allows both styles. Which way's better for maximum compatibility?

    Richard (TIA)
    Last edited by Richardcavell; 03-23-2011 at 04:50 AM. Reason: add code tags

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Use the first one.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    May 2010
    Location
    Naypyidaw
    Posts
    1,314
    I believe it's not called compound literal. Compound Literal
    Btw, both of them are supported in C89.
    Last edited by Bayint Naung; 03-23-2011 at 06:22 AM.

  4. #4
    Registered User
    Join Date
    Feb 2011
    Posts
    144
    Right, I assumed what "compound literal" meant, incorrectly. My bad.

    I think the "This " "string" ".\n" technique seems much better.

    Richard

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Modifying a string literal.
    By Eman in forum C++ Programming
    Replies: 45
    Last Post: 12-30-2010, 06:37 PM
  2. Button handler
    By Nephiroth in forum Windows Programming
    Replies: 8
    Last Post: 03-12-2006, 06:23 AM
  3. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM

Tags for this Thread