Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Include and code on same line in C

Tags:

c

include

I want a code in one line only. I haven't found something usefull for the moment.

Exemple, I have:

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

And I'm searching something like:

#include <unistd.h>;int function(){write(1,"abcdefghijkmnopqrstuvwxyz\n",27);return(0);}
like image 881
Glastis Avatar asked Dec 02 '22 16:12

Glastis


2 Answers

You can't. The #include preprocessing directive must be followed by a newline. It's part of the syntax (6.10.1 in the C standard http://open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf).

It's generally okay to omit headers from your one-liner, although even better to make the code compile without headers. If someone is going to plug your one-liner into a compiler, they'll know enough to fix a missing header or two.

like image 52
QuestionC Avatar answered Dec 05 '22 07:12

QuestionC


Such code violates the C standard. Per section 6.10, an #include preprocessor directive takes the form:

# include pp-tokens new-line

Note that the new line is required.

like image 30
Andrew Henle Avatar answered Dec 05 '22 05:12

Andrew Henle