Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8899165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T00:47:38+00:00 2026-06-15T00:47:38+00:00

When compiling this: // external definitions int value1 = 0; static int value2 =

  • 0

When compiling this:

// external definitions
int value1 = 0;
static int value2 = 0;

the gcc compiler generates the following assembly:

.globl value1
        .bss
        .align 4
        .type   value1, @object
        .size   value1, 4
value1:
        .zero   4
        .local  value2
        .comm   value2,4,4

However, when i initialize the variables to a value other than zero such as:

// external definitions
int value1 = 1;
static int value2 = 1;

the gcc compiler generated the following:

.globl value1
        .data
        .align 4
        .type   value1, @object
        .size   value1, 4
value1:
        .long   1
        .align 4
        .type   value2, @object
        .size   value2, 4
value2:
        .long   1

My questions are:

  1. Why in the first case the values are allocated in the bss segment while in the second case in the data segment.
  2. Why value2 variable is defined as .local and .comm in the first case, while not in the second.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T00:47:39+00:00Added an answer on June 15, 2026 at 12:47 am

    Generally speaking, the bss section contains uninitialized values and the data section contains initialized values. However, gcc places values that are initialized to zero into the bss section instead of the data section, as the bss section is zeroed out in runtime anyway, it doesn’t make much sense to store zeros in the data section, this saves some disk space, from man gcc:

    -fno-zero-initialized-in-bss If the target supports a BSS section, GCC by default puts variables that are initialized to zero into BSS. This
    can save space in the resulting code.
    This option turns off this
    behavior because some programs explicitly rely on variables going to
    the data section

    I’m not sure why .comm is used with static storage which is local to an object file, it is usually used to declare common symbols that, if not defined/initialized, should be merged by the linker with symbol that have the same name from other object files and that’s why it’s not used in the second example because the variables are initialized, from the as manual

    .comm declares a common symbol named symbol. When linking, a common
    symbol in one object file may be merged with a defined or common
    symbol of the same name in another object file

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Recently I tried compiling program something like this with GCC: int f(int i){ if(i<0){
Consider the following C program, 'pause.c': void main() { pause(); } Compiling this on
I get this problem while compiling my code. Error 14 error LNK2019: unresolved external
Compiling this code with g++ 4.7.0 ( -Wall -Wextra -Werror -Wconversion -std=c++11 ): #include
cout << boolalpha (1 < 0) << endl; I was compiling this recently as
Why is this not compiling? error C2660: 'Concrete::WriteLine' : function does not take 1
I get an undefined reference to 'typeof'-error compiling and linking this: #include <stdio.h> #include
I get this error when compiling a C# application. Looks like a trivial error,
While compiling a program in Java I got this big WARNING warning: [unchecked] unchecked
This is the output I'm getting while compiling my class under Lubuntu 12.04 32bit

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.