From: Aaron Rocha <hxdg21@yahoo.com>
To: gcc-help@gcc.gnu.org
Subject: Warning when using const pointer to fixed size array
Date: Mon, 30 Nov 2009 23:19:00 -0000 [thread overview]
Message-ID: <959717.71134.qm@web110612.mail.gq1.yahoo.com> (raw)
I am using :
$ gcc -dumpversion
4.2.4
$ gcc -dumpmachine
x86_64-linux-gnu
As expected, the following code does not generate any warnings when compiling with -Wall:
int main() {
int number = 0;
const int * const t = &number;
return *t;
}
However, this code does:
int main() {
int array[9] = {0};
const int (* const p)[9] = &array;
return (*p)[0];
}
$ gcc -Wall ./tst2.c
./tst2.c: In function ‘main’:
./tst2.c:7: warning: initialization from incompatible pointer type
In order to eliminate this warning, I have to declare array as:
const int array[9];
Why is this the case though? In both examples, I am trying to use a const pointer to access a non-const variable for read-only purposes. Isn't this supposed to be OK?
Thanks
__________________________________________________________________
Looking for the perfect gift? Give the gift of Flickr!
http://www.flickr.com/gift/
next reply other threads:[~2009-11-30 23:19 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-11-30 23:19 Aaron Rocha [this message]
2009-11-30 23:38 ` Thomas Martitz
2009-11-30 23:47 ` me22
2009-12-01 0:05 ` Thomas Martitz
2009-12-01 0:08 ` me22
2009-12-01 0:24 ` Aaron Rocha
2009-12-01 0:44 ` me22
2009-12-01 2:29 ` One question about gcc fix_includes He Yunlong-B20256
2009-12-01 9:34 ` Andrew Haley
2009-12-02 2:37 ` He Yunlong-B20256
2009-12-02 9:40 ` Andrew Haley
2009-12-02 9:43 ` Kai Ruottu
2009-12-07 8:25 ` He Yunlong-B20256
2009-12-01 0:08 ` Warning when using const pointer to fixed size array Thomas Martitz
2009-12-01 9:52 ` Andrew Haley
2009-12-01 14:54 ` Aaron Rocha
2009-12-01 15:08 ` Sergei Organov
2009-12-01 15:19 ` me22
2009-12-01 16:25 ` Sergei Organov
2009-12-01 16:29 ` me22
2009-12-01 16:42 ` Sergei Organov
2009-12-01 15:33 ` Andrew Haley
2009-12-01 15:43 ` Aaron Rocha
2009-12-01 16:22 ` Andrew Haley
2009-12-01 18:16 ` Aaron Rocha
2009-12-01 15:57 ` John (Eljay) Love-Jensen
2009-12-01 15:59 ` John (Eljay) Love-Jensen
2009-12-01 16:00 ` Andrew Haley
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=959717.71134.qm@web110612.mail.gq1.yahoo.com \
--to=hxdg21@yahoo.com \
--cc=gcc-help@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).