This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
auto const ints and pointer issue
- From: Karen Shaeffer <shaeffer at neuralscape dot com>
- To: gcc at gnu dot org
- Cc: shaeffer at neuralscape dot com
- Date: Tue, 17 Jun 2008 10:42:22 -0700
- Subject: auto const ints and pointer issue
Hi,
I have stumbled upon a quirk that appears to me to be
illogical. Maybe someone can help me to understand this:
~~~~~~~~~~~~~~~~ sample code ~~~~~~~~~~~~~~~~~~~~~~~~~
#include <stdio.h>
const int gic = 0;
const int * gcip;
int * gip;
int main(int argc, char * argv[]) {
const int ic = 0;
const int * cip;
int * ip;
cip = ⁣
ip = (int *)cip;
*ip = 5;
printf("const int ic = %d *cip = %d *ip = %d\n", ic, *cip, *ip);
printf("&ic = %p cip = %p ip = %p\n", &ic, cip, ip);
gcip = &gic;
gip = (int *)gcip;
#if 0
*gip = 5;
printf("global const int gic = %d *gcip = %d *gip = %d\n",
gic, *gcip, *gip);
printf("&gic = %p gcip = %p gip = %p\n", &gic, gcip, gip);
#endif
return 0;
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~ output ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$ const_ints
const int ic = 0 *cip = 5 *ip = 5
&ic = 0xbfbd72a0 cip = 0xbfbd72a0 ip = 0xbfbd72a0
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The global variable code would segfault, as I expected. But the
auto variable code gives this illogical result. I would appreciate
comments. I am not on this list, so please ensure I am cc'd with
any responses. I'll be happy to file a bug, if it is a bug.
Thanks,
Karen
--
Karen Shaeffer
Neuralscape, Palo Alto, Ca. 94306
shaeffer@neuralscape.com http://www.neuralscape.com