When is a variable of static type in C language assigned value?

Source: Internet
Author: User

The answer should be a compile-time assignment.

Verification process:

Write a C-language program as follows:

#include "stdio.h"

int main () {
static int i;
static int j=0x12345678;

printf ("%02x", ih[t]);
return 0;
}

Compile with GCC to generate the target file: Gcc-c test_static.c-o TEST_STATIC.O

The static variable is positioned the same as the global variable. If it is an initialized static variable, it is stored in the. Data segment, and if it is uninitialized, it is stored in the. BSS segment.

Use Objdump to view the generated target files.

Objdump-t TEST_STATIC.O


You can see the symbol and segment information in the destination file.

Objdump-j. Data-s TEST_STATIC.O

The following information is displayed:



Attached: Common objdump commands:

Objdump-t obj file name: The symbol table for the output destination file
Objdump-h obj file name: summary of all segments of the output destination file
Objdump-j. text/.data-s obj file name: Output information for the specified segment


When is a variable of static type in C language assigned value?

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.