From mboxrd@z Thu Jan 1 00:00:00 1970 From: mayur nande Subject: Re: C question Date: Thu, 8 Oct 2009 08:32:01 +0530 Message-ID: References: <7783925d0910071912u5e4f4a2au8442cb6537cd35ed@mail.gmail.com> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=000e0cd5f674fef9fa047563af9e Return-path: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type; bh=lVUkBuqI1xJfkf10BrxS1O/TYjc8doMdnzVeWRk0AGc=; b=yEC1fPxW0A6K2qOaO0CbJyp7QS7C1fytMgyZjT1qvOEuAvnoK2dYA1nrKvF/P+KNZy gYhIs4ZH4BdG11S9COeANB2giJCKM7Z89dswwb9NxCVou9l9MguUzUyPGClFwi6FMwT4 i2cIjN1TreZsC8kJTAAw2VDgzSo0VhBCWD0yc= In-Reply-To: <7783925d0910071912u5e4f4a2au8442cb6537cd35ed@mail.gmail.com> Sender: kernelnewbies-bounce@nl.linux.org Errors-to: kernelnewbies-bounce@nl.linux.org List-help: List-unsubscribe: List-software: Ecartis version 1.0.0 List-Id: List-subscribe: List-owner: List-post: List-archive: To: Rick Brown Cc: kernelnewbies , linux-newbie@vger.kernel.org --000e0cd5f674fef9fa047563af9e Content-Type: text/plain; charset=ISO-8859-1 Hi Rick, Some days ago i had the same question in my mind. While going through "The Linux Kernel Architecture" book (by Wolfgang Mauerer), i got the answer: The GNU compiler supports arithmetic with void pointers as well as function pointers. The increment step is 1 byte. These are used by the kernel at various points. Have fun. Regards Mayur On Thu, Oct 8, 2009 at 7:42 AM, Rick Brown wrote: > Hello list, > > As far as I recall from K&R, isn't pointer arithmetic on a void > pointer banned? And any effort to do that results in an error - > because the compiler won't know by how much size to increment the > pointer for a statement like "ptr++"? But then how about this: > > [rick@linux rick]$ cat t.c > #include > int main() > { > void *ptr = 0; > printf("%d \n", ptr+1); > } > [rick@linux rick]$ gcc t.c > [rick@linux rick]$ ./a.out > 1 > [rick@linux rick]$ > > It compiles and runs fine ... ! > > TIA, > > Rick > > -- > To unsubscribe from this list: send an email with > "unsubscribe kernelnewbies" to ecartis@nl.linux.org > Please read the FAQ at http://kernelnewbies.org/FAQ > > --000e0cd5f674fef9fa047563af9e Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Hi Rick,

Some days ago i had the same question in my mind. While goi= ng through "The Linux Kernel Architecture" book (by Wolfgang Mau= erer), i got the answer:

The GNU compiler supports arithmetic with v= oid pointers as well as function pointers. The increment step is 1 byte. Th= ese are used by the kernel at various points.

Have fun.

Regards
Mayur

On= Thu, Oct 8, 2009 at 7:42 AM, Rick Brown <rick.brown.3@gmail.com> wrote:<= br>
Hello list,

As far as I recall from K&R, isn't pointer arithmetic on a void
pointer banned? And any effort to do that results in an error -
because the compiler won't know by how much size to increment the
pointer for a statement like "ptr++"? But then how about this:
[rick@linux rick]$ cat t.c
#include <stdio.h>
int main()
{
=A0 =A0void *ptr =3D 0;
=A0 =A0printf("%d \n", ptr+1);
}
[rick@linux rick]$ gcc t.c
[rick@linux rick]$ ./a.out
1
[rick@linux rick]$

It compiles and runs fine ... !

TIA,

Rick

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@nl.linux.org
Please read the FAQ at http://kernelnewbies.org/FAQ


--000e0cd5f674fef9fa047563af9e-- -- To unsubscribe from this list: send an email with "unsubscribe kernelnewbies" to ecartis@nl.linux.org Please read the FAQ at http://kernelnewbies.org/FAQ