From: mayur nande <mayur.nan@gmail.com>
To: Rick Brown <rick.brown.3@gmail.com>
Cc: kernelnewbies <kernelnewbies@nl.linux.org>, linux-newbie@vger.kernel.org
Subject: Re: C question
Date: Thu, 8 Oct 2009 08:32:01 +0530 [thread overview]
Message-ID: <f86e1f200910072002o3a08ca64h4a9bc70dd33d0e7c@mail.gmail.com> (raw)
In-Reply-To: <7783925d0910071912u5e4f4a2au8442cb6537cd35ed@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 1137 bytes --]
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 <rick.brown.3@gmail.com> 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 <stdio.h>
> 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
>
>
[-- Attachment #2: Type: text/html, Size: 1715 bytes --]
next prev parent reply other threads:[~2009-10-08 3:02 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-10-08 2:12 C question Rick Brown
2009-10-08 2:52 ` Manish Katiyar
2009-10-08 5:37 ` Kalpesh Rathod
2009-10-08 8:48 ` Michał Nazarewicz
2009-10-08 3:02 ` mayur nande [this message]
2009-10-08 5:43 ` sandeep lahane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=f86e1f200910072002o3a08ca64h4a9bc70dd33d0e7c@mail.gmail.com \
--to=mayur.nan@gmail.com \
--cc=kernelnewbies@nl.linux.org \
--cc=linux-newbie@vger.kernel.org \
--cc=rick.brown.3@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox