[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: FSFS/svn-rep-sharing-stats questions

From: Stefan Sperling <stsp_at_elego.de>
Date: Tue, 13 Oct 2009 11:24:03 +0100

On Tue, Oct 13, 2009 at 04:58:29AM +0200, Daniel Shahaf wrote:
> Branko Cibej wrote on Tue, 13 Oct 2009 at 04:39 +0200:
> > Daniel Shahaf wrote:
> > > Was trying to avoid malloc'ing an unsigned int. But, indeed, I can't
> > > find a reference allowing the cast. So I have two options:
> > >
> > > * malloc an unsigned int
> > >
> > > * use pointer arithmetic:
> > > def increment():
> > > void *p = apr_hash_get();
> > > apr_hash_set(p+1)
> > > def extract_final_value():
> > > void *p = apr_hash_get();
> > > return (p - NULL)
> > >
> >
> > Which is not strictly well-defined, either. :) void* doesn't have a
> > size, so you can't do arithmetic with it (never mind GCC's extension).
> >
>
> First, we use sizeof(void *) in our code.

Well, sizeof(void *) asks for the size of a generic pointer which has
constant size for a given architecture.

But in case of pointer arithmetic, e.g. "struct foo *p; ...; p++;",
you want the increment to skip the number of bytes in struct foo
("point at the next foo"). It refers to the size of the data structure
being pointed at, not the size of the pointer itself.

Stefan

-- 
Don't wait! Buy my new book "C for Subversion Developers" today!
Place your orders at http://stsp.name/C-for-Subversion-Developers.html
Exclusive discount for full committers.
Every purchase includes a 10% donation to the Subversion Corporation.
------------------------------------------------------
http://subversion.tigris.org/ds/viewMessage.do?dsForumId=462&dsMessageId=2407022
Received on 2009-10-13 23:31:11 CEST

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.