C language macro

Source: Internet
Author: User

The ansi c standard has several predefined macros: __file _ date _ time ___ _ line _.

_ Line __: inSource codeInsert Current SourceCodeRow number;

_ File __: insert the name of the current source file into the source file;

_ Date __: Insert the current compilation date into the source file

_ Time __: Insert the current compilation time into the source file;

_ Stdc __: when requiredProgramWhen the ansi c standard is strictly followed, this identifier is assigned a value of 1;

_ Cplusplus: This identifier is defined when a C ++ program is compiled.

These macros are useful ~~~~~~~~

When debugging a program or compiling a program, __line _ is useful. It can be used to print the line numbers of logical errors ~~~~~~~, Example:

Switch (X)

{

Case 1:

....;

Break;

 

Case 2:

.....;

Break;

 

Default:

Printf ("logic erro line number % d! /N ",__ line __);

Break;

}

Another example is to use _ date _ and _ time _ to insert the Compilation Time.

Code:

Void print_version_info (void)

{

Printf ("date compiled: % s/n" ,__ date __);

Printf ("timecompiled: % s/n" ,__ time __);

}

Output Format: Mm dd yy and HH: mm: SS

In this way, you can implement version control and know when you have compiled it ~~

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.