Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Backslash newline at end of file warning

Tags:

c++

With this code:

#include <iostream>


int main(int argc, char *argv[])
{

  return 0;
}


/** run2: A macro to call a function. */
#define run2( function, ctype, dim ) \
if ( operation == #function ) \
{ \
  if ( componentType == #ctype && Dimension == dim ) \
  { \
    typedef itk::Image< ctype, dim > ImageType; \
    function< ImageType >( inputFileName, outputFileName, radius, algorithm, useCompression ); \
    supported = true; \
  } \
}

I get a warning: backslash-newline at end of file

Any idea how to make it go away?

David

like image 283
David Doria Avatar asked Apr 18 '11 20:04

David Doria


People also ask

How do I fix warning no newline at end of file?

Open the file in an editor, go to the last line of the file, and hit enter to add a blank line to the end of the file. Though, besides that, you should be using #include <iostream> instead of <iostream. h> . Then put in a using std::cout; after it.

What is backslash newline?

A backslash before a newline indicates that the next line is a continuation, as if the newline wasn't there (particularly useful for #define which would normally be on one line).

Which Slash is used for new line in C?

Solution: The backslash (\) character is used as the continuation character to continue #define statements and strings to the next line. GCC expects the backslash character to be the very last character on the line.


1 Answers

The problem is that there's no new-line character in the end of your code. C++ Standard §2.1/2 says:

<...>If a source file that is not empty does not end in a new-line character, or ends in a new-line character immediately preceded by a backslash character, the behavior is undefined.

like image 172
Kirill V. Lyadvinsky Avatar answered Oct 09 '22 03:10

Kirill V. Lyadvinsky