Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 30 Apr 2002 11:11:38 -0700 (PDT)
From:      Francis Jordan <francrj@yahoo.com>
To:        Dag-Erling Smorgrav <des@ofug.org>
Cc:        freebsd-chat@freebsd.org
Subject:   Re: strange gcc warning
Message-ID:  <20020430181138.37192.qmail@web20403.mail.yahoo.com>
In-Reply-To: <xzpheltrxp5.fsf@flood.ping.uio.no>

next in thread | previous in thread | raw e-mail | index | archive | help
Hi Dag-Erling,

The warning goes away when I wrap the array in a
struct, but I still don't understand it clearly.
If the array is converted to a pointer, isn't it
safe to cast a regular pointer to a pointer to
const (i.e. a read-only pointer)?

If I write:

void foo(const int *p) {}

int main()
{
   int *i = 0;

   foo(i);
   return 0;
}

there is no warning.

Thanks

FRJ


--- Dag-Erling Smorgrav <des@ofug.org> wrote:
> Francis Jordan <francrj@yahoo.com> writes:
> > This may seem like a newbie question, but still --
> why
> > does the following produce a warning:
> > 
> > void
> > foo(const int b[8][8])
> > {
> > }
> 
> Arrays degenerate to pointers when passed as
> arguments to functions.
> You can wrap it in a struct if you want to keep the
> size information;
> otherwise foo() will have to do the necessary
> pointer arithmetic "by
> hand".
> 
> DES
> -- 
> Dag-Erling Smorgrav - des@ofug.org


__________________________________________________
Do You Yahoo!?
Yahoo! Health - your guide to health and wellness
http://health.yahoo.com

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-chat" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020430181138.37192.qmail>