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

  • Home
  • SEARCH
  • 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 649939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:59:55+00:00 2026-05-13T21:59:55+00:00

When I write the following program: file 1: #include <stdio.h> int global; void print_global1()

  • 0

When I write the following program:

file 1:

#include <stdio.h>    
int global;    
void print_global1() {
        printf("%p\n", &global);
}

file 2:

#include <stdio.h>
char global;    
void print_global2() {
        printf("%p\n", &global);
}

file 3:

void print_global1();
void print_global2();
int main()
{
        print_global1();
        print_global2();

        return 0;
}

output:

$ ./a.out
0x804a01c
0x804a01c

Here is my question:

  • Why are the linker implementing “int global” and “char global” as the same global variable:
  • How come the compiler does not complain (not the smallest warning with -Wall -Wextra -ansi …)
  • How are the size of the global variable managed (the size of int and char are different)

PS: The second question is architecture/compiler related, so lets take the gcc or Visual C++ (for C) with the int size as 32 bits

EDIT: THIS IS NOT A QUESTION FOR C++ BUT for C!

I use gcc version 4.4.1 and on Ubuntu 9.10, Here is the compilation console output:

$ ls
global_data1.c  global_data2.c  global_data.c

$ gcc -Wall -Wextra -ansi global_data*.c
$ ./a.out
0x804a01c
0x804a01c
or 
$ gcc -Wall -Wextra -ansi -c global_data*.c
$ gcc -Wall -Wextra -ansi global_data*.o
$ ./a.out
0x804a01c
0x804a01c
  • 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-05-13T21:59:55+00:00Added an answer on May 13, 2026 at 9:59 pm

    gcc does not report any error/warnings. But g++ does.

    EDIT:

    Looks like C allows tentative definitions for a variable.

    In your case both the global definitions are tentative and in that case the first one seen by the linker is chosen.

    Change your file2 to:

    char global = 1; // no more tentative...but explicit.
    

    Now if you compile like before, the tentative def in file1 will be ignored.

    Make both the def explicit by:

    int global = 1; // in file1
    
    char global = 1; // in file2
    

    now neither can be ignored and we get the multiple def error.

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

Sidebar

Ask A Question

Stats

  • Questions 323k
  • Answers 323k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Your output shows that you're getting a TransformerConfigurationException; according to… May 14, 2026 at 12:57 am
  • Editorial Team
    Editorial Team added an answer you need some way to distinguish latest comment, so I… May 14, 2026 at 12:57 am
  • Editorial Team
    Editorial Team added an answer Within Rails' implementation of REST new and create are treated… May 14, 2026 at 12:57 am

Related Questions

This is probably a really easy question to answer, but for some reason I'm
Right now I am working on a stub of a project. In the course
please correct the program. Q. Write a java prg to accept RollNo, Name of
I am an author of an Open Source project, which is released under GPL2.
Lets say I have an array numbers that contains the following values: int numbers

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.