Include and code on one line in C

I need code in only one line. At the moment, I have not found anything useful.

For example, I have:

#include <unistd.h>
int function(){write(1,"abcdefghijkmnopqrstuvwxyz\n",27);return(0);}

And I'm looking for something like:

#include <unistd.h>;int function(){write(1,"abcdefghijkmnopqrstuvwxyz\n",27);return(0);}
+4
source share
3 answers

You can not. Before the preprocessing directive, a #includenew line should follow. This is part of the syntax (6.10.1 in the C standard http://open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf ).

As a rule, you can omit the headers from your single-line image, although it is even better to make the code compiled without headers. If someone is going to connect your one-line key to the compiler, they will know enough to fix the missing header or two.

+7

C. 6.10 #include :

# include pp-tokens new-line

, .

+5

You can change the compilation command to output the output trto gccor clang:

#include <unistd.h> @ int function(){write(1,"abcdefghijkmnopqrstuvwxyz\n",27);return(0);}

Compile with:

cat myfile.c | tr @ '
' | clang -x c99 -c -o myfile.o -
+3
source

Source: https://habr.com/ru/post/1609496/


All Articles