This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: is this a valid approach to aliasing?


Robert William Fuller wrote:
John Love-Jensen wrote:
Hi Robert,

Can you just get rid of the void** for the items parameter (see below)?

--Eljay

#include <stdlib.h>

int reallocItems(
  void* items,
  int itemSize,
  int* itemAlloc,
  int numItems,
  int newItems,
  int itemHint)
{
  void* rcAlloc;
  int emptyItems;
  int allocItems;

  // for idempotence
  allocItems = *itemAlloc;

  // will the new entries fit?
  emptyItems = allocItems - numItems;

if (newItems > emptyItems)
{
// allocate the number of entries needed or the hint, whichever is more
allocItems = numItems + newItems;


    if (itemHint > allocItems)
    {
      allocItems = itemHint;
    }

rcAlloc = realloc(items, allocItems * itemSize);

    if (rcAlloc)
    {
      *(void**)items = rcAlloc;

This code is probably wrong. Make item a void** and get rid of the cast.


Andrew.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]