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: quick question


hmm, I just thought, how about an int pointer instead

char *make_superstring(int size)
{
  int *superstring = (int*)malloc(2 * sizeof(int) + size * sizeof(char);
  return (char*)(superstring + 2 * sizeof(int));
}

-Jim

On 2/16/06, Jim Stapleton <stapleton.41@gmail.com> wrote:
> which rules are you referring to? I've not seen that one.
>
> On 2/16/06, Brian Dessent <brian@dessent.net> wrote:
> > Jim Stapleton wrote:
> >
> > >   char test[] =  {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
> > > 0x08, 0x09, 0x0a};
> > >   char *tptr = test;
> > >   int *ptr;
> > >
> > >   ptr = (int*)tptr;
> >
> > Doesn't this violate the C aliasing rules?  If so the whole thing is
> > undefined behavior.
> >
> > Brian
> >
>


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