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 6161081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:25:17+00:00 2026-05-23T21:25:17+00:00

Compiling this code snippet with gcc (4.5) and as many -Wall, -Wextra, -Wuninitialized type

  • 0

Compiling this code snippet with gcc (4.5) and as many -Wall, -Wextra, -Wuninitialized type flags turned on as possible gives me no warnings:

int main() {
    int *p = p;
    printf("p = %p\n", (void *)p);
    return 0;
}

But running it multiple times gives this output:

p = 0xbe9ff4
p = 0x550ff4
p = 0xeb1ff4
p = 0x4caff4

… and so on.

What’s going on here?

EDIT: Compiling with “g++ -Wall” instead gives me warning as I’d expect:

In function ‘int main()’: warning: ‘p’ is used uninitialized in this function
  • 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-23T21:25:17+00:00Added an answer on May 23, 2026 at 9:25 pm
    int *p = p;
    

    p is defined as soon as int *p is parsed, but the RHS is only evaluated afterwards. This statement is equivalent to

    int * p;
    p = p;
    

    This is different in C++ with implicit constructors, but in plain ol’ C, this is what you have. Undefined initial value.

    As far as the compiler warning goes, it’s a Quality Of Implementation issue. gcc isn’t being “tricked”, it’s just being permissive.

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

Sidebar

Related Questions

Take this non-compiling code for instance: public string GetPath(string basefolder, string[] extraFolders) { string
I get this message when compiling C++ on gcc 4.3 error: ‘NULL’ was not
Recently I tried compiling program something like this with GCC: int f(int i){ if(i<0){
I have a code snippet that looks like this: [tableView beginUpdates]; [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
Environment: VS2005 C++ using STLPort 5.1.4. Compiling the following code snippet: std::string copied =
I have the following code snippet. I am compiling using the sun studio 12
When compiling this code I get the following error : In function 'int main()':
I just downloaded this PHP Code Snippet Library scrpt from http://www.sourceforge.net/projects/php-csl/ , when I
I have this snippet of code here. The intention is to make a copy
I am having issues getting this piece of code to compile. I am compiling

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.