How to create a compound literal for maximum compatibility

This is a discussion on How to create a compound literal for maximum compatibility within the C Programming forums, part of the General Programming Boards category; Hi all. One can create a long string literal like this: Code: char *mystring = "This is all one" " ...

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

    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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,555
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  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
    126
    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, 05:37 PM
  2. Button handler
    By Nephiroth in forum Windows Programming
    Replies: 8
    Last Post: 03-12-2006, 05: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


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21