Predefined Macro Names. McGraw-Hill The Complete Reference Fourth Edition
Реклама
Реклама
250
C + + : T h e C o m p l e t e R e f e r e n c e into printf("%d", xy);
If these operators seem strange to you, keep in mind that they are not needed or used in most programs. They exist primarily to allow the preprocessor to handle some special cases.
Predefined Macro Names
C++ specifies six built-in predefined macro names. They are
_ _LINE_ _
_ _FILE_ _
_ _DATE_ _
_ _TIME_ _
_ _STDC_ _
_ _cplusplus
The C language defines the first five of these. Each will be described here, in turn.
The _ _LINE_ _ and _ _FILE_ _ macros were described in the discussion of #line.
Briefly, they contain the current line number and filename of the program when it is being compiled.
The _ _DATE_ _ macro contains a string of the form month/day/year that is the date of the translation of the source file into object code.
The _ _TIME_ _ macro contains the time at which the program was compiled. The time is represented in a string having the form hour:minute:second.
The meaning of _ _STDC_ _ is implementation-defined. Generally, if _ _STDC_ _ is defined, the compiler will accept only standard C/C++ code that does not contain any nonstandard extensions.
A compiler conforming to Standard C++ will define_ _cplusplus as a value containing at least six digits. Nonconforming compilers will use a value with five or less digits.
Comments
C89 defines only one style of comment, which begins with the character pair /* and ends with */. There must be no spaces between the asterisk and the slash. The compiler
C h a p t e r 1 0 : T h e P r e p r o c e s s o r a n d C o m m e n t s
251 ignores any text between the beginning and ending comment symbols. For example, this program prints only hello on the screen:
#include <stdio.h> int main(void)
{ printf("hello");
/* printf("there"); */
} return 0;
This style of comment is commonly called a multiline comment because the text of the comment may extend over two or more lines. For example,
/* this is a multi-line comment */
Comments may be placed anywhere in a program, as long as they do not appear in the middle of a keyword or identifier. For example, this comment is valid: x = 10+ /* add the numbers */5; while swi/*this will not work*/tch(c) { ...
is incorrect because a keyword cannot contain a comment. However, you should not generally place comments in the middle of expressions because it obscures their meaning.
Multiline comments may not be nested. That is, one comment may not contain another comment. For example, this code fragment causes a compile-time error:
/* this is an outer comment x = y/a;
*/
/* this is an inner comment - and causes an error */
Изтегляне
Реклама