Newsgroup: comp.lang.c


Date: Fri, 14 Apr 2006 00:38:05 +0300
From: Diomidis Spinellis <dds@aueb.gr>
Organization: Athens University of Economics and Business
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.1) Gecko/20060130 SeaMonkey/1.0
MIME-Version: 1.0
Newsgroups: comp.lang.c
Subject: Re: Incrementing a void pointer. Legal C99?
References: <443EBF9B.55C939D8@mega-nerd.com>
In-Reply-To: <443EBF9B.55C939D8@mega-nerd.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Erik de Castro Lopo wrote:
> The GNU C compiler allows a void pointer to be incremented and
> the behaviour is equivalent to incrementing a char pointer.
> 
> Is this legal C99 or is this a GNU C extention?

C99 (6.5.6) defines the addition of an integer to a pointer in terms of 
a pointer pointing to an element of an array: after the addition of N 
the pointer will point N elements forward (subject to array size 
restrictions).  C99 (6.2.5) also says that void is an incomplete type, 
which means that arrays of that type can not be constructed.  My 
understanding from these two facts is that C99 doesn't define pointer 
arithmetic with a void pointer.

Note that gcc -ansi -pedantic will issue a warning:

warning: wrong type argument to increment

-- 
Diomidis Spinellis
Code Quality: The Open Source Perspective (Addison-Wesley 2006)
http://www.spinellis.gr/codequality



Newsgroup comp.lang.c contents
Newsgroup list
Diomidis Spinellis home page

Creative Commons License Unless otherwise expressly stated, all original material on this page created by Diomidis Spinellis is licensed under a Creative Commons Attribution-Share Alike 3.0 Greece License.