Scope of typedef and define

Source: Internet
Author: User

typedef :

If it is placed outside all functions, its scope is from the beginning of its definition until the end of the file;

If placed within a function, the defined field is defined from the beginning of the definition until the end of the function;

#define :

Scopes are defined from the beginning of the definition to the end of the entire file, whether within a function or outside of all functions.

Such as:

typedef ...//Start here to end of file

#define ...//start here to end of file

int negate (int num)

{

...

typedef ...//Start here to the end of the function. Note that in this function, before this definition, it cannot be used

#define ...//start here to end of file

...

}

typedef ...//Start here to end of file

#define ...//start here to end of file

void Show ()

{

typedef ...//Start here to the end of the function.

#define ...//start here to end of file

}

...

Summarize:

(1) Whether it is a typedef or a define, it cannot be used before the definition;

(2) the typedef is affected by the function range, and the define is not affected;

(3) whether it's a typedef or define ? , its scope does not extend to other files, even different files of the same program, and cannot be used with each other.

Scope of typedef and define

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.