The #line in C language

Source: Internet
Author: User

#line指令用于改变 the contents of __line__ and __file__.

Both __line__ and __file__ are predefined identifiers in the compiler, where the content of the identifier __line__ is the line number of the currently compiled line of code, and the __file__ content is the file name of the currently compiled source file.

#line的一般形式是: #line number "filename"

Where number is a positive integer and becomes the new value of __line__; the optional "filename" is the legal file identifier and becomes the new value of the __file__.

#line主要用于调试和特殊应用.

#line的使用实例:

1#include <stdio.h>2 #line"NewFileName"3 intMain ()//From here the number is4{//2015printf"%s\n", __file__);//#line重命名文件为NewFileName6printf"%d\n", __line__);//line number is 2037printf"%d\n", __line__);//2048printf"%d\n", __line__);//2059     return 0;Ten}

The result of the operation is:

NewFileName 203 204 205
Note: __date__: Used to record the date the source file was compiled into an executable file __time__: Used to record when the source file was compiled into an executable __stdc__: Indicates whether the compiler uses ANSI C standard viewing: printf ("%s\n", __date_ _);//Date the file was compiled
printf ("%s\n", __time__);//time to compile the file
printf ("%d\n", __stdc__);//Indicates whether the compiler uses ANSI C standards

The #line in 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.