Bug 71746 - Scope Variable Address (Stack) Mismatch
Summary: Scope Variable Address (Stack) Mismatch
Status: CLOSED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 5.3.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-07-04 01:11 UTC by Furkan USLU
Modified: 2016-07-04 01:27 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Furkan USLU 2016-07-04 01:11:37 UTC
int main()
{
    int* ptr;
    {
        int svar = 13;
        ptr = &svar;
    }
    int mvar = 144;
    printf("%d\n", *ptr);

output is 13 but if i add this line (after or before printf)

int* p = &mvar;

output is 144.
Comment 1 Andrew Pinski 2016-07-04 01:14:46 UTC
svar leaves the scope so the address of it becomes invalid.  Any access to that address is undefined.
Comment 2 Furkan USLU 2016-07-04 01:27:54 UTC
--