ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
A continued line is a line which ends with a backslash, \ . The backslash is removed and the following line is joined with the current one. No space is inserted, so you may split a line anywhere, even in the middle of a word. (It is generally more readable to split lines only at white space.)
To expand on what pan64 posted, in C preprocessor syntax a #define statement includes everything up to the first newline character. The \ hides the newline character which lets the definition extend across multiple lines in the source file.
It is important that the \ be the very last character on the line. A common error that can be difficult to see is having a space follow the \ so that the newline is no longer hidden.
To expand on what pan64 posted, in C preprocessor syntax a #define statement includes everything up to the first newline character. The \ hides the newline character which lets the definition extend across multiple lines in the source file.
It is important that the \ be the very last character on the line. A common error that can be difficult to see is having a space follow the \ so that the newline is no longer hidden.
Does this line extension trick work in normal C code, or is used only in any macro (C) preprocessor?
If only in macro (C) preprocessor, then the next question IS: how is any macro preprocessor; or specifically, the C macro preprocessor coded?
Any source book, or site for the same, is requested.
Does this line extension trick work in normal C code, or is used only in any macro (C) preprocessor?
What do you mean by normal c code, what is the non-normal c code?
the preprocessing phase is completely automatic, when you start to compile your code it will be first preprocessed (by the tool named cpp).
Quote:
Originally Posted by ajiten
If only in macro (C) preprocessor, then the next question IS: how is any macro preprocessor; or specifically, the C macro preprocessor coded?
Any source book, or site for the same, is requested.
Does this line extension trick work in normal C code, or is used only in any macro (C) preprocessor?
As pan64 has already pointed out, suppression of newlines by a \ is a fairly common practice in the Unix/Linux world.
Whitespace, including newlines is not significant in the C language so in general there is no need to suppress them.
But, preprocessing directives, by definition, are lines bounded by a # character as the first non-whitespace character and terminated by a newline character. So, to format those across multiple lines for readability you must suppress all but the final bounding newline.
Quote:
Originally Posted by ajiten
If only in macro (C) preprocessor, then the next question IS: how is any macro preprocessor; or specifically, the C macro preprocessor coded?
Any source book, or site for the same, is requested.
I would recommend K&R The C Programming Language, Second Edition (ANSI edition) which has a very complete section about the C preprocessor.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.