public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Karen Shaeffer <shaeffer@neuralscape.com>
To: gcc@gnu.org
Cc: shaeffer@neuralscape.com
Subject: auto const ints and pointer issue
Date: Tue, 17 Jun 2008 17:43:00 -0000	[thread overview]
Message-ID: <20080617174222.GA19409@synapse.neuralscape.com> (raw)

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 = &ic;
  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

             reply	other threads:[~2008-06-17 17:43 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-17 17:43 Karen Shaeffer [this message]
2008-06-17 18:02 ` Ian Lance Taylor
2008-06-17 19:38   ` Karen Shaeffer
2008-06-18  6:11     ` Re[2]: " Dmitry I. Yanushkevich
2008-06-18 10:20     ` Andrew Haley
2008-06-18 14:47       ` Karen Shaeffer
2008-06-18  1:44   ` Karen Shaeffer
2008-06-18  1:52     ` Andrew Pinski
2008-06-18  3:52       ` Karen Shaeffer
2008-06-18  4:35         ` Ian Lance Taylor
2008-06-18 12:53         ` jlh
2008-06-18 16:42         ` Joe Buck
2008-06-18 17:05           ` Karen Shaeffer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080617174222.GA19409@synapse.neuralscape.com \
    --to=shaeffer@neuralscape.com \
    --cc=gcc@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).