Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 326529 - when assigning a value to pointee, pointer changes as well
Summary: when assigning a value to pointee, pointer changes as well
Status: RESOLVED INVALID
Alias: None
Product: CDT
Classification: Tools
Component: cdt-build (show other bugs)
Version: 8.0   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: cdt-build-inbox@eclipse.org CLA
QA Contact: Andrew Gvozdev CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-09-29 09:04 EDT by MIke CLA
Modified: 2010-09-29 11:38 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description MIke CLA 2010-09-29 09:04:51 EDT
Build Identifier: 20100617-1415

When practicing dynamic allocation, I wrote some code as follows: 
	int *p, *q;
	int arr[] = {1,2,3,4,5};
	p=arr;
	q=p+5;
	*q=6;

After the last sentence was exercised, the reference of "p" also changed to "0x06". It seems that when I gave "*q" an assignment, the reference of "p" was assigned with 6 too, while it should not change.

Reproducible: Always

Steps to Reproduce:
1. reference assignment of a pointer-to-integer "p" with an array "arr"
2. assign "p+5" to another pointer-to-integer "q"
3. assign an integer, say 6, to "*q"

Through debug, you can see that value of "p" changes to "0x06" as well
Comment 1 Andrew Gvozdev CLA 2010-09-29 11:38:34 EDT
The bug is in your code, not in CDT. p+5 refers outside of the array. Apparently that particular compiler allocates p itself at that memory location, i.e. at the point of initialization.