Forums.ATC.no

Teknisk => Generelt teknisk => Emne startet av: ATC på 27. ſeptember 2008, 18:24 pm

Tittel: gcc: Multiline strings cause complaint about missing string terminator
Skrevet av: ATC27. ſeptember 2008, 18:24 pm
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);
Tittel: [Solved] gcc: Multiline strings cause complaint about missing string terminator
Skrevet av: ATC27. ſeptember 2008, 18:24 pm
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?