On Fri, Aug 09, 2024 at 03:42:06PM +0200, Jakub Jelinek via Gcc wrote:
> On Fri, Aug 09, 2024 at 03:25:00PM +0200, Alejandro Colomar wrote:
> > The problem with that is that the error will still be enforced _after_
> > GCC would change the behavior of sizeof(aparam).
> 
> I don't think it should unless C2Y requires that.
> 
> > Admittedly, I could write configure checks to determine if I have a
> > version of GCC where sizeof(aparam) is bad and only enable the error
> > there.
> > 
> > > but there is nothing wrong about using sizeof on function
> > > argument with array type if you know what you're doing,
> > 
> > I have doubts here.  Does anyone have an idea of what kind of program
> > would be interested in that value?
> 
> Any time you use some macro on such parameters where the macro internals use
> sizeof for whatever reason.
> E.g. if it wants to cast the pointer to some integer type and decides based
> on sizeof what integer type that would be, ...
> I mean, what you are suggesting is similar to making an error from
> sizeof (char), that is by definition 1, so there is no point for users to
> use it.  It makes sense in macros...

E.g. consider GCC
#define iterative_hash_object(OB,INIT) iterative_hash (&OB, sizeof (OB), INIT)
macro.
If one uses it on the function parameters declared as arrays but turned into
pointers and you know what you are doing, why not.
If using sizeof in that case is an error, you'd need to know, I can use this
macro on everything except this special case.

        Jakub

Reply via email to