public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/63643] New: pointer to const variable doesn't allow to change its value (on Mac OS)
@ 2014-10-25 11:41 romain.wallon at orange dot fr
  2014-10-25 11:47 ` [Bug c/63643] " dominiq at lps dot ens.fr
  2014-10-26  1:40 ` redi at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: romain.wallon at orange dot fr @ 2014-10-25 11:41 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63643

            Bug ID: 63643
           Summary: pointer to const variable doesn't allow to change its
                    value (on Mac OS)
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: romain.wallon at orange dot fr

Created attachment 33806
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=33806&action=edit
A program which tests changing a const value with a pointer.

For example, when a variable i is declared as const int, and p is declared as
int *, it is impossible to change the value of i by *p, whereas ANSI norm
allows it.
More over, it seems to be two differents value at the same address. Here is the
result of a test:

0x7fff5720dbf8 : 0
0x7fff5720dbf8 : 12

You'll find the program in attachment.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c/63643] pointer to const variable doesn't allow to change its value (on Mac OS)
  2014-10-25 11:41 [Bug c/63643] New: pointer to const variable doesn't allow to change its value (on Mac OS) romain.wallon at orange dot fr
@ 2014-10-25 11:47 ` dominiq at lps dot ens.fr
  2014-10-26  1:40 ` redi at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: dominiq at lps dot ens.fr @ 2014-10-25 11:47 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63643

Dominique d'Humieres <dominiq at lps dot ens.fr> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |WAITING
   Last reconfirmed|                            |2014-10-25
     Ever confirmed|0                           |1

--- Comment #1 from Dominique d'Humieres <dominiq at lps dot ens.fr> ---
On x86_64-apple-darwin14 (Yosemite) I get

0x7fff58ce0414 : 12
0x7fff58ce0414 : 12

When compiling the test with -Wall -Wextra -pedantic I get

pr63643.c: In function 'main':
pr63643.c:7:9: warning: format '%p' expects argument of type 'void *', but
argument 2 has type 'const int *' [-Wformat=]
  printf("%p : %d\n", &i, i);
         ^
pr63643.c:7:9: warning: format '%p' expects argument of type 'void *', but
argument 2 has type 'const int *' [-Wformat=]
pr63643.c:8:9: warning: format '%p' expects argument of type 'void *', but
argument 2 has type 'int *' [-Wformat=]
  printf("%p : %d\n", p, *p);
         ^
pr63643.c:8:9: warning: format '%p' expects argument of type 'void *', but
argument 2 has type 'int *' [-Wformat=]


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c/63643] pointer to const variable doesn't allow to change its value (on Mac OS)
  2014-10-25 11:41 [Bug c/63643] New: pointer to const variable doesn't allow to change its value (on Mac OS) romain.wallon at orange dot fr
  2014-10-25 11:47 ` [Bug c/63643] " dominiq at lps dot ens.fr
@ 2014-10-26  1:40 ` redi at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: redi at gcc dot gnu.org @ 2014-10-26  1:40 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63643

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|WAITING                     |RESOLVED
         Resolution|---                         |INVALID

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
The program is invalid. The C standard says "An assignment operator shall have
a modifiable lvalue as its left operand." An object with a const-qualified type
is not a modifiable lvalue.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-10-26  1:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-25 11:41 [Bug c/63643] New: pointer to const variable doesn't allow to change its value (on Mac OS) romain.wallon at orange dot fr
2014-10-25 11:47 ` [Bug c/63643] " dominiq at lps dot ens.fr
2014-10-26  1:40 ` redi at gcc dot gnu.org

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).