_ FUNCTION __, _ line _ helps with the macro definition of DEBUG

Source: Internet
Author: User


_ FUNCTION __, _ line __



Today, I have no intention of seeing a piece of code, which contains such a snippet:

 
If (! Interface) {err ("% s-error, can't find device for minor % d", _ FUNCTION __, subminor); retval =-enodev; goto exit ;}

What does _ function _ do? Rare (my level is not enough ~), Interesting ~

Later I found out that this is a macro definition associated with the GCC compiler. These macro definitions help to quickly locate the location where the Program Reports errors or warnings, number of rows in the file (_ line __)



Demo

/*************************************** * ********* Code writer: eofcode Date: 2014.08.17code file: macro_demo.ce-mail: [email protected] Code purpose: this code is a demo for how to use some special macros -- _ file _ function _ line____date __. it's funny and useful to use this macroto help you to debug. if there is something wrong with my code, please touch me by e-mail. **************************************** * *********/# include <stdio. h> void Hello (void) {printf ("_ file _: % S _ FUNCTION __: % S _ line __: % d _ date __: % s \ n ",__ file __,__ function __,__ line __,__ date _);} int main () {printf (" _ file __: % S _ FUNCTION __: % S _ line __: % d _ date __: % s \ n ",__ file __,__ function __,__ line __, __date _); Hello (); Return 0 ;}




Note that the macro definition here will not change according to the runtime environment. No matter which directory I am running this demo, the _ file _ printed characters will always prompt. /Hello. c thinks it is still the current directory. In fact, the runtime environment has changed.


Of course, these macro definitions are very helpful for debugging.










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.