How to mark a region so clang-format won't touch it?

For example, in the MySQL++ library there are macros that can be used to define simple structs based on sql table definition, like this:

sql_create_6(stock, 1, 6,
mysqlpp::sql_char, item,
mysqlpp::sql_bigint, num,
mysqlpp::sql_double, weight,
mysqlpp::sql_decimal, price,
mysqlpp::sql_date, sdate,
mysqlpp::Null<mysqlpp::sql_mediumtext>, description)

The problem is that clang-format will reformat this in a way that is much more difficult to read (every param on a new line). Most code formatters can recognize special format-off / format-on comments, but I haven't found anything like that in the clang-format manual.

29719 次浏览

Try adding a // comment marker after each line, this may do it. I had the same issue in Eclipse and learned this trick.

sql_create_6(stock, 1, 6, //
mysqlpp::sql_char, item, //
mysqlpp::sql_bigint, num, //
mysqlpp::sql_double, weight, //
mysqlpp::sql_decimal, price, //
mysqlpp::sql_date, sdate, //
mysqlpp::Null<mysqlpp::sql_mediumtext>, description)

In newer version, you can surround a section of code with:

// clang-format off
...
// clang-format on

I noticed that
//clang-format off didn't work but
// clang-format off did!
The space after // made all the difference in VS code. I don't think this is in any way related to VS code.