C + + Drip

Source: Internet
Author: User

1\\ C + + macros:

???? (1) # The function is to use the following macro parameters for string operation (stringfication);

???? Eg: #define WARN_IF (EXP)????

???? do{if (EXP)????

???????????????? fprintf (stderr, "Warning:" #EXP "\ n");}???

??????? ? while (0)

???? Wern_if (value = = 0);

???? expanded to :

???? do{

???????? if (value = = 0)

???????? fprintf (stderr, "warning:valude = = 0");

????} while (0);

???? (2) # # Connector ( concatenator ), used to set two of the token ( Mark ) connected to a token, Action object is no longer limited to macro parameters Span style= "font-family: Song body; Background-color:white "> can also be used with

???????? #define DECLARE_HANDLE (name) struct name# #__ {int unused;}; typedef struct name# #__ *name ( The pointer type for redefining the struct name# #__ is name)

???? Declare_handle (HWND);

???? HWND HD;

???? will get a struct pointer ;

???? --------------------------------------

???? Note : where the macro definition has # or ## the Place , macro parameters are not expanded

???? #define A 2;

???? #define PARAM (A) #A # #_;

???? printf ("%s", PARAM (A));

???? Get printf ("%s", A_);???? Compile error

???? macro Parameters A will not be unfolded as expected. 2_????

???? (3) C language predefined macros :

???? __date__
????
date that the preprocessing was made ("Mmm dd yyyy"form of string literals)

???? __file__
????
string literal representing the current source code file name

???? __line__
????
An integer constant representing the line number in the current source code

???? __time__
????
source file compilation time, Lattice micro"HH:mm:SS "

???? __FUNCTION__ (__fucn__)
????
name of current function?

???? __date__, __time__ Yes build time if rebuild program __date__, __time__ and it changed.

2\\typedef:

???? structint__

???? {

???????? int A;

????};

???? typedefint__* pit;???????? // redefine int__ pointer type to pit

???? typedef int__ it

???? Pit pt = NULL;

???? Pt->a = 1000;

C + + Drip

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.