Re: How to fix strict-aliasing with functions that use void**

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Stephen Hill wrote:
> I'm a newbie to GCC 4.x and I am getting lots of warnings about type
> punning with code that use void** (I am using -O3).
> I have functions declared to perform dynamic memory allocation that use
> void**:
> 
>   bool RiMalloc(void **pBlock, int nSize);
>   void RiFree(void **pBlock);
> 
> So, for example, we call the functions thus:
> 
>   typedef struct {
>      int x;
>      int y;
>   } tWibble;
> 
>   tWibble* void test_func(void)
>   {       tWibble* pZ = NULL;
>      if (RiMalloc(&pZ, sizeof(tWibble)))
>      {
>         pZ->x = 5;
>         pZ->y = 10
>      }
>      return pZ;
>   }
> 
> Compiling this code with strict-aliasing enabled produces a warning.

I get:

p.c: In function 'test_func':
p.c:13: warning: passing argument 1 of 'RiMalloc' from incompatible pointer type

So this is a different case from the one that produces the strict-aliasing
warning.  This is a hard error, not a warning.  What is the real strict-aliasing
code?

Andrew.





#include <stddef.h>

int RiMalloc(void **pBlock, int nSize);
void RiFree(void **pBlock);

typedef struct {
  int x;
  int y;
} tWibble;

tWibble* test_func(void)
{       tWibble* pZ = NULL;
  if (RiMalloc(&pZ, sizeof(tWibble)))
    {
      pZ->x = 5;
      pZ->y = 10;
    }
  return pZ;
}

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux