Ano-Tech Computers
Enter keyword:

gcc: Multiline strings cause complaint about missing string terminator
Problem:
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);
 
Solution:
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?
 
Discuss this solution
Did this article solve your problem? Yes No Did not apply

We welcome anyone who is willing to contribute to this public knowledge base, contact siteadmin@atc.no if you have information you would like to share. The idea is not to replace the commercial support sites, but to publish those hard-to-find solutions you've found yourself looking for over and over again.

Show all articles