Thread: arrays of strings

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    1

    Question arrays of strings

    I recently came across an unfamiliar piece of code.

    Code:
    char *filter[] = {\
    "LOW","HIGHP","BANDP","ALLP"\
    };
    I just wanted to ask, what's with the backslashes? Never seen it before, but it looks useful. I mean is it something old which isn't really done anymore, or is it commom? Thanks.

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    It's called a line continuation marker and tells the preprocessor to append the following line to the current line. So if you ran that code through just the preprocessor stage of the compilation process and spit out the results, you'd see:
    Code:
    char *filter[] = {"LOW","HIGHP","BANDP","ALLP"};
    Basically, it just allows you to break up a single line into multiple lines for readability purposes. In this case, it doesn't really matter when all is said and done because the compiler ignores white space and would give you the same machine code either way. But if you're creating macros (using #define), then those are handled by the preprocessor and require the line continuation markers to be there if your macro spans multiple lines.

    e.g.:
    Code:
    // VALID
    #define FOO(m) puts(m);
    Code:
    // INVALID
    #define FOO(m)
      puts(m);
    Code:
    // VALID
    #define FOO(m)\
      puts(m);
    Last edited by itsme86; 03-03-2011 at 01:22 AM.
    If you understand what you're doing, you're not learning anything.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Two-dimensional arrays with strings
    By Niels_M in forum C Programming
    Replies: 25
    Last Post: 08-02-2010, 04:02 PM
  2. Replies: 2
    Last Post: 02-23-2004, 06:34 AM
  3. working with strings arrays and pointers
    By Nutka in forum C Programming
    Replies: 4
    Last Post: 10-30-2002, 08:32 PM
  4. strings or character arrays
    By Shadow12345 in forum C++ Programming
    Replies: 2
    Last Post: 07-21-2002, 10:55 AM
  5. Searching arrays for strings
    By Zaarin in forum C++ Programming
    Replies: 14
    Last Post: 09-03-2001, 06:13 PM