This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/25702] feature request: generate a warning for sizeof on a pointer
- From: "meklund at cisco dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 6 Jan 2006 22:24:35 -0000
- Subject: [Bug c/25702] feature request: generate a warning for sizeof on a pointer
- References: <bug-25702-11981@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #2 from meklund at cisco dot com 2006-01-06 22:24 -------
Subject: Re: feature request: generate a warning for sizeof on a pointer
On Fri, Jan 06, 2006 at 10:12:55PM -0000, pinskia at gcc dot gnu dot org wrote:
> Actually people use sizeof(x) all the time to mean the correct thing, for an
> example: memcpy(&x, y, sizeof(x));
True, and that is why I'd like to make it an optional warning. People
would be up in arms if it weren't optional. But, for people that want
to avoid this easily missed problem, they could live with
memcpy(&x, y, sizeof(xtype *))
I have seen one instance where people would consider it annoying:
char *m[] = { "this", "is", "bothersome", "to", "some" };
int m_items = sizeof(m) / sizeof(*m);
but once again, the avoidance of having unexpectedly short lengths
would override the annoyance for many.
How about I apply my patch and do a large build like BSD "make world"
and come back with a listing of how prevalent the above is?
--mark
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25702