__LINE__ macros in the C language

Source: Internet
Author: User

In the C language, there are four predefined macros:

Current file: __file__

Current line number: __line__

Current Date: __date__

Current time: __time__

These 4 macros are replaced by the compiler with actual values or strings when the code is compiled.

Here is a snippet of code that compiles a code: TEST.C

1 #include <stdio.h>2void  main ()3{4     printf ("  %s \ n%d \n%s \ n%s \ n", __file__,__line__,__date__,__time__); 5 }

The result of his operation is:

test.c   4  about     £ º

Only the line number is an integer, the other 3 is a string , it is very convenient to use it!

__file__,__line__ is useful when debugging a program ;

__date__,__time__ is useful when confirming the program compile time (version reference ).

Original articles, reproduced please indicate the source.

__LINE__ macros in the C language

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.