Skrevet av Emne: gcc: Multiline strings cause complaint about missing string terminator  (Lest 2310 ganger)

ATC

  • Gjest
  • [applaud]0
  • [smite]0
  • For some odd reason, the people behind gcc have seen fit to break backward compatibility by no longer allowing multi-line string constants like in this code:

      snprintf(querystring, MAXQRYLEN, "
        SELECT login FROM connections
        LEFT JOIN contacts ON (contact = contactid)
        WHERE id = '%s'
        AND pin = '%s'
      ", conn, pin);



    ATC

    • Gjest
  • [applaud]0
  • [smite]0
  • Rewrite like this:

      snprintf(querystring, MAXQRYLEN,
        "SELECT login FROM connections "
        "LEFT JOIN contacts ON (contact = contactid) "
        "WHERE id = '%s' "
        "AND pin = '%s' "
      , conn, pin);

    Notice those trailing spaces, if you forget one you'll be debugging for hours :-|

    The code is uglier and harder to maintain, but if you really cared you would be using Perl instead of C in the first place.... right?