gcc.c-torture/execute/pr22098-1.c

Michael Meissner meissner@linux.vnet.ibm.com
Wed Nov 19 16:18:00 GMT 2008


On Tue, Nov 18, 2008 at 06:32:56PM -0500, DJ Delorie wrote:
> 
> Like this?  (a bigger size_t is OK for this test)
> 
> extern void abort (void);
> extern void exit (int);
> typedef __SIZE_TYPE__ size_t;
> int
> main (void)
> {
>   int a = 0;
>   int *p;
>   size_t b;
>   if (sizeof (size_t) < sizeof (int *))
>     exit (0);
>   b = (size_t)(p = &(int []){0, 1, 2}[++a]);
>   if (a != 1 || *p != 1 || *(int *)b != 1)
>     abort ();
>   exit (0);
> }

Yes.

>From a standards point of view, I don't think you could ever have sizeof
(size_t) being larger than sizeof (void *).  But it is ok if some port
somewhere makes size_t larger than a point.

-- 
Michael Meissner, IBM
4 Technology Place Drive, MS 2203A, Westford, MA, 01886, USA
meissner@linux.vnet.ibm.com



More information about the Gcc-patches mailing list