This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/25702] feature request: generate a warning for sizeof on a pointer



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



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]