# Pragma weak

Source: Internet
Author: User

Use# Pragma weakIn name format, the Command makes name a weak symbol. When the link program does not find the symbolic definition of name, no error message is displayed, and multiple weakly defined error messages of the symbol are not displayed. The linked program only executes the first definition encountered.

If another compilation unit has a strong definition of a function or variable, the name is linked to it. If there is no strong definition of name, the value of the link program symbol is 0.

Example1

Compilation unit A cu1.c

<Stdio. h> weak foo * = & (ptr =

Compilation Unit B cu2.c

Foo =;

Compile unit A only:Gcc cu1.c &./a. outTo execute the if statement.

Compile two units:Gcc cu1.c cu2.c &./a. outTo execute the else statement.

Example2

Cu3.c

<Stdio. h> foo (weak foo (foo! =

CompileGcc cu3.c &./a. out, Prompting that foo is not defined.

Example3

Compilation unit A cu4.c

<Stdio. h> foo (foo1 (weak foo = foo1

Compilation Unit B cu5.c

<Stdio. h> foo (

Compile unit A only:Gcc cu4.c &./a. outRun foo1.

Compile two units:Gcc cu4.c cu5.c &./a. outRun foo.

Related Article

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.