You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by tr...@apache.org on 2002/01/10 03:10:13 UTC

cvs commit: apr/shmem/unix shm.c

trawick     02/01/09 18:10:13

  Modified:    shmem/unix shm.c
  Log:
  get some pointer arithmetic to compile on picky compilers
  
  Revision  Changes    Path
  1.2       +1 -1      apr/shmem/unix/shm.c
  
  Index: shm.c
  ===================================================================
  RCS file: /home/cvs/apr/shmem/unix/shm.c,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- shm.c	10 Jan 2002 00:20:06 -0000	1.1
  +++ shm.c	10 Jan 2002 02:10:13 -0000	1.2
  @@ -153,7 +153,7 @@
           /* store the real size in the metadata */
           *(apr_size_t*)(new_m->base) = new_m->realsize;
           /* metadata isn't usable */
  -        new_m->usable = new_m->base + sizeof(apr_size_t);
  +        new_m->usable = (char *)new_m->base + sizeof(apr_size_t);
   
           *m = new_m;
           return APR_SUCCESS;
  
  
  

Re: cvs commit: apr/shmem/unix shm.c

Posted by "William A. Rowe, Jr." <wr...@covalent.net>.
From: "Aaron Bannert" <aa...@clove.org>
Sent: Thursday, January 10, 2002 12:31 AM


> >   -        new_m->usable = new_m->base + sizeof(apr_size_t);
> >   +        new_m->usable = (char *)new_m->base + sizeof(apr_size_t);
> 
> What a weird compiler -- it complains about type agreement for addition
> expressions, but not for LHS/RHS agreement on assignment expressions?
> 
> (I suppose it minds adding anything to a void*, but doesn't mind assigning
> a char* to a void*.)

No... that's actually the proper definition.  A void has no size, correct?
So you cannot add the sizeof(* (void*foo)) + x.  By rights, compilers who
assume sizeof(* (void*)) == 1 are actually broken :)

On the other side, void* can be assigned to any * type, while any * type
can be assigned to a void*.  This is really poor practice, but entirely
legal according to spec.  It's the reason void*'s are usually poor choices.


Re: cvs commit: apr/shmem/unix shm.c

Posted by Aaron Bannert <aa...@clove.org>.
On Thu, Jan 10, 2002 at 02:10:13AM -0000, trawick@apache.org wrote:
> trawick     02/01/09 18:10:13
> 
>   Modified:    shmem/unix shm.c
>   Log:
>   get some pointer arithmetic to compile on picky compilers
>   
>   Revision  Changes    Path
>   1.2       +1 -1      apr/shmem/unix/shm.c
>   
>   Index: shm.c
>   ===================================================================
>   RCS file: /home/cvs/apr/shmem/unix/shm.c,v
>   retrieving revision 1.1
>   retrieving revision 1.2
>   diff -u -r1.1 -r1.2
>   --- shm.c	10 Jan 2002 00:20:06 -0000	1.1
>   +++ shm.c	10 Jan 2002 02:10:13 -0000	1.2
>   @@ -153,7 +153,7 @@
>            /* store the real size in the metadata */
>            *(apr_size_t*)(new_m->base) = new_m->realsize;
>            /* metadata isn't usable */
>   -        new_m->usable = new_m->base + sizeof(apr_size_t);
>   +        new_m->usable = (char *)new_m->base + sizeof(apr_size_t);

What a weird compiler -- it complains about type agreement for addition
expressions, but not for LHS/RHS agreement on assignment expressions?

(I suppose it minds adding anything to a void*, but doesn't mind assigning
a char* to a void*.)

-aaron